伙計們,我正在 tkinter 中撰寫 GUI。我想處理點擊事件,就像用戶在 GUI 上使用“左”滑鼠按鈕時一樣。這是為了在用戶點擊時播放聲音。那么是否有任何功能,例如:
onClick(lambda: play()) #call a function
提前致謝 :)
uj5u.com熱心網友回復:
您可以將單擊事件添加到畫布。
像這樣的東西應該作業:
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474306.html
下一篇:未定義Tkinter頂層視窗
