3
我正在編寫我的第一個GUI應用程序以查找公司的產品。Python將無法識別屬性
from Tkinter import *
import tkMessageBox
def debug():
buttonText = relStatus.get()
tkMessageBox.showinfo("You Clicked ", buttonText)
return
app = Tk()
app.title("Ironcraft Product Finder")
app.geometry("700x500")
labelText = StringVar()
labelText.set("Choose an Appliance Type")
topLabel = Label(app, textvariable = labelText, height = 5).pack()
fire = Button(app, text="Fire", width=20, command=debug)
fire.pack(padx=10)
relStatus = StringVar()
relStatus.set(fire.text)
app.mainloop()
當我運行它,它出現並顯示錯誤消息:
AttributeError: Button instance has no attribute 'text'
但在創作「火」的,它說
text="fire"
這不是一個屬性?
謝謝,永遠不會有我自己的:) – cjm 2012-08-15 09:44:38