Python Tkinter正在给我一个_Tkinter.TclError:当我尝试运行它时,错误的事件类型或keysym“button”
我跟随Tkinter的教程,试图运行我的程序,但启动时程序崩溃了Python Tkinter正在给我一个_Tkinter.TclError:当我尝试运行它时,错误的事件类型或keysym“button”,python,tkinter,Python,Tkinter,我跟随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("<butt
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等等
错误就是告诉你到底出了什么问题。按钮不是有效的事件。这是按钮。
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()