【发布时间】:2013-03-20 16:05:11
【问题描述】:
我是 Tkinter 和 Python 3.3 的新手,并试图开发一个简单的 GUI。我有一个标签“statusLabel”。当我单击按钮时,我想更新按钮回调中标签中的值,但出现错误。
line 12, in reportCallback
statusLabel.config(text="Thank you. Generating report...")
AttributeError: 'NoneType' object has no attribute 'config'
下面是我的代码
from tkinter import *
root = Tk()
Label(root,text="Project folders. Include full paths. One project per line").pack()
Text(root,height=4).pack()
Label(root,text="Standard project subfolders. Include path from project.").pack()
Text(root,height=4).pack()
statusLabel = Label(root,text="Oh, hello.").pack()
def reportCallback():
statusLabel.config(text="Thank you. Generating report...")
b = Button(root, text="Generate Report", command=reportCallback).pack()
root.mainloop()
【问题讨论】:
-
如果你想在一个定义的函数中使用你的 statusLabel (它没有在那里定义 -> NoneType),你是否应该让你的 statusLabel 全局化
标签: python callback tkinter label config