为什么我的python编辑器不能工作
我下载了pycharm,并将youtube教程中的一些代码复制到其中,这对制作视频的人很有效,但当我尝试运行它时,它不起作用,它是这样说的:为什么我的python编辑器不能工作,python,tkinter,Python,Tkinter,我下载了pycharm,并将youtube教程中的一些代码复制到其中,这对制作视频的人很有效,但当我尝试运行它时,它不起作用,它是这样说的: C:\Python27\python.exe C:/Python27/Lib/site-packages/wheel/test/test245425232.py Traceback (most recent call last): File "C:/Python27/Lib/site-packages/wheel/test/test245425232.
C:\Python27\python.exe C:/Python27/Lib/site-packages/wheel/test/test245425232.py
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/wheel/test/test245425232.py", line 9, in <module>
button1.bind("<button1>", printName)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1098, in bind
return self._bind(('bind', self._w), sequence, func, add)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1053, in _bind
self.tk.call(what + (sequence, cmd))
_tkinter.TclError: bad event type or keysym "button1"
Process finished with exit code 1
C:\Python27\python.exe C:/Python27/Lib/site-packages/wheel/test/test245425232.py
回溯(最近一次呼叫最后一次):
文件“C:/Python27/Lib/site packages/wheel/test/test245425232.py”,第9行,在
button1.bind(“,printName)
文件“C:\Python27\lib\lib tk\Tkinter.py”,第1098行,在bind中
返回self.\u bind(('bind',self.\u w),sequence,func,add)
文件“C:\Python27\lib\lib tk\Tkinter.py”,第1053行,在_bind中
self.tk.call(what+(sequence,cmd))
_tkinter.TclError:错误的事件类型或keysym“button1”
进程已完成,退出代码为1
代码如下:
from tkinter import *
root=Tk()
def printName():
print("hi stuff")
button1=Button(root, text="print my name")
button1.bind("<button1>", printName)
button1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
def printName():
打印(“hi-stuff”)
button1=按钮(root,text=“打印我的名字”)
button1.bind(“,printName)
按钮1.pack()
root.mainloop()
最好是:
button1.bind("<Button-1>", printName)
(“Button-1”是鼠标左键单击事件的名称,而不是小部件变量名)
否则,您需要使用一个参数声明函数printName
:绑定给定的事件
def printName(event):
print("hi stuff")
button1=Button(root, text="print my name")
button1.bind("<Button-1>", printName)
def printName(事件):
打印(“hi-stuff”)
button1=按钮(root,text=“打印我的名字”)
button1.bind(“,printName)
正如我所说,像这样的绑定对于另一个小部件来说是有意义的:
from tkinter import *
root=Tk()
def printName(event):
print("hi stuff")
label1=Label(root, text="print my name")
label1.bind("<Button-1>", printName)
label1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
def打印名(事件):
打印(“hi-stuff”)
label1=标签(root,text=“打印我的名字”)
label1.bind(“,printName)
标签1.pack()
root.mainloop()
最好是:
button1.bind("<Button-1>", printName)
(“Button-1”是鼠标左键单击事件的名称,而不是小部件变量名)
否则,您需要使用一个参数声明函数printName
:绑定给定的事件
def printName(event):
print("hi stuff")
button1=Button(root, text="print my name")
button1.bind("<Button-1>", printName)
def printName(事件):
打印(“hi-stuff”)
button1=按钮(root,text=“打印我的名字”)
button1.bind(“,printName)
正如我所说,像这样的绑定对于另一个小部件来说是有意义的:
from tkinter import *
root=Tk()
def printName(event):
print("hi stuff")
label1=Label(root, text="print my name")
label1.bind("<Button-1>", printName)
label1.pack()
root.mainloop()
从tkinter导入*
root=Tk()
def打印名(事件):
打印(“hi-stuff”)
label1=标签(root,text=“打印我的名字”)
label1.bind(“,printName)
标签1.pack()
root.mainloop()
我认为您必须添加tkinter库才能使其工作。我认为您必须添加tkinter库才能使其工作。