【发布时间】:2019-08-22 03:42:17
【问题描述】:
我正在尝试学习 python GUI,但我不知道如何绑定东西。
from tkinter import *
root = Tk()
def leftClick(event):
print("Left click")
frame = Frame(root,width=300,height=250).pack()
frame.bind("<Button-1>", leftClick)
root.mainloop()
但是……
Traceback (most recent call last):
File "gui2.py", line 8, in <module>
frame.bind("<Button-1>", leftClick)
AttributeError: 'NoneType' object has no attribute 'bind'
【问题讨论】:
-
将
frame = Frame(root,width=300,height=250).pack()更改为frame = Frame(root,width=300,height=250)并添加frame.pack() -
@eyllanesc 是正确的,
pack()返回None。
标签: python tkinter python-3.7