Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Tkinter正在给我一个_Tkinter.TclError:当我尝试运行它时,错误的事件类型或keysym“button”_Python_Tkinter - Fatal编程技术网

Python Tkinter正在给我一个_Tkinter.TclError:当我尝试运行它时,错误的事件类型或keysym“button”

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

我跟随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等等


错误就是告诉你到底出了什么问题。按钮不是有效的事件。这是按钮。
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()