1
我對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) – chill0r 2013-03-20 16:09:09