我正在尝试通过按钮命令创建一个新的 TopLevel,但是,我遇到了一些困难。使用以下代码:
initial_state_button = Button(current_state, text=current_state_text, command = partial(initial_state_display, aatsplusv))
initial_state_button.pack(side = TOP)
....
def initial_state_display(dictionary):
top = Toplevel()
top.title = "About this State:"
count = 0
for key, value in dictionary["initial states"].iteritems():
proposition = Message(top, text = key)
proposition.grid(row=count, column=0, padx=5, pady=5)
colon = Message(top, text = " : ")
colon.grid(row=count, column=1, padx=5, pady=5)
boolean = Message(top, text = str(value))
colon.grid(row=count, column=2, padx=5, pady=5)
count += 1
我收到以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1536, in __call__ return self.func(*args)
File "Assignmentest.py", line 400, in initial_state_display top = Toplevel()
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2136, in __init__ self.title(root.title())
TypeError: 'str' object is not callable
我不知道出了什么问题。top = Toplevel 完全按照 effbot 示例所示的方式编写。Python 2.7 中不提供顶层吗?如果是这样,是否有 2.7 等价物?