简体   繁体   English

当我尝试运行它时,Tkinter 给了我一个 _tkinter.TclError: bad event type or keysym "button"

[英]Tkinter is giving me a _tkinter.TclError: bad event type or keysym "button" when i try to run it

I was following along with a tutorial on Tkinter and i tried to run my program and it crashes on startup.我正在关注 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()

I have looked at my code and the code from the video and i cant seem to find anything different that would cause python to give me a error.我查看了我的代码和视频中的代码,我似乎找不到任何不同的东西会导致 python 给我一个错误。 I am not sure if it is because i am using a newer version(because the video itself was made back in 2014) or if its some mistype.我不确定是因为我使用的是较新版本(因为视频本身是在 2014 年制作的)还是输入错误。

The correct name for mouse click events are Button-1 and so on .... .鼠标单击事件的正确名称是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.

相关问题 无法摆脱 (_tkinter.TclError: bad event type or keysym &quot;UP&quot;) 问题 - Couldn't get rid of (_tkinter.TclError: bad event type or keysym "UP") problem 我在销毁按钮时收到错误 _tkinter.TclError: bad window path name “.!button” - I get the error _tkinter.TclError: bad window path name “.!button” when I destroy the button _tkinter.TclError:错误的窗口路径名“.!button2” - _tkinter.TclError: bad window path name ".!button2" 错误:_tkinter.TclError:错误的窗口路径名“.!button” - Errror: _tkinter.TclError: bad window path name ".!button" Tkinter -tkinter.TclError - Tkinter -tkinter.TclError _tkinter.TclError: 错误的窗口路径名 - _tkinter.TclError: bad window path name _tkinter.TclError: 错误的屏幕距离“.!startpage” - _tkinter.TclError: bad screen distance ".!startpage" 这是什么“_tkinter.TclError: bad option”。 谁能告诉我我做错了什么并告诉我如何解决这个问题? - What is this “_tkinter.TclError: bad option”. can anybody tell me what I've done wrong and tell me how to fix this? _tkinter.TclError:当我单击列表框中的项目时 - _tkinter.TclError: when I click on an item from the listbox Python tkinter:错误 _tkinter.TclError:错误的窗口路径名“.!button2” - Python tkinter: error _tkinter.TclError: bad window path name ".!button2"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM