[英]Is there a click event handler in tkinter?
伙計們,我正在 tkinter 中編寫 GUI。 我想處理點擊事件,就像用戶在 GUI 上使用“左”鼠標按鈕時一樣。 這是為了在用戶點擊時播放聲音。 那么是否有任何功能,例如:
onClick(lambda: play()) #call a function
提前致謝 :)
您可以將單擊事件添加到畫布。
像這樣的東西應該工作:
root = Tk()
def on_click(event):
print("you clicked")
canvas = Canvas(root, width=800, height=600)
canvas.bind("<Button-1>", on_click)
canvas.pack()
# Canvas.focus_set is required if the window already contains a widget that has keyboard/input focus
canvas.focus_set()
root.mainloop()
以下是使用此方法的一些示例: https ://python-course.eu/tkinter/events-and-binds-in-tkinter.php
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.