【发布时间】:2011-01-03 07:45:45
【问题描述】:
我正在尝试使用 ttk.Button 的调用方法,如 TkDocs 所示(查看“命令回调”),但我不断收到此错误:
AttributeError: 'NoneType' 对象没有属性 'invoke'
所以,我在 Interactive Shell 中尝试了这个:
ActivePython 3.1.1.2 (ActiveState Software Inc.) based on
Python 3.1.1 (r311:74480, Aug 17 2009, 12:30:13) [MSC v.1500 32 bit (Intel)] on
win32
>>> from tkinter import *
>>> import tkinter.ttk as ttk
>>> root = Tk()
>>> button = ttk.Button(root, text="Test").grid(row=0, column=0)
>>> print(button)
None
这表明 ttk.Button 返回 None。
ttk.Button 是否意味着返回 None。而且,如果是这样,为什么 TkDocs 会说有一个 invoke 方法?
【问题讨论】:
-
为了记录,这也发生在非 ttk 小部件上,如果您使用
pack而不是grid。