[英]Couldn't get rid of (_tkinter.TclError: bad event type or keysym "UP") problem
[英]Tkinter is giving me a _tkinter.TclError: bad event type or keysym "button" when i try to run it
我正在關注 Tkinter 的教程,我試圖運行我的程序,但它在啟動時崩潰了。
mainwindow = Tk()
def leftclick(event):
print("left")
def middleclick(event):
print("middle")
def rightclick(event):
print("right")
frame = Frame(mainwindow, width=300, height=250)
frame.bind("<button-1>", leftclick)
frame.bind("<button-2>", middleclick)
frame.bind("<button-3>", rightclick)
frame.pack()
mainwindow.mainloop()
我查看了我的代碼和視頻中的代碼,我似乎找不到任何不同的東西會導致 python 給我一個錯誤。 我不確定是因為我使用的是較新版本(因為視頻本身是在 2014 年制作的)還是輸入錯誤。
鼠標單擊事件的正確名稱是Button-1 and so on ....
from tkinter import *
mainwindow = Tk()
def leftclick(event):
print("left")
def middleclick(event):
print("middle")
def rightclick(event):
print("right")
frame = Frame(mainwindow, width=300, height=250)
frame.bind("<Button-1>", leftclick)
frame.bind("<Button-2>", middleclick)
frame.bind("<Button-3>", rightclick)
frame.focus_set()
frame.pack()
mainwindow.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.