我正在编写我的第一个GUI应用程序来查找公司的产品。
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"
这不是一个属性吗?
答案 0 :(得分:5)
答案 1 :(得分:0)
topLabel = Label(app, textvariable = labelText, height = 5).pack() # so topLabel is None
topLabel = Label(app, textvariable = labelText, height = 5)
topLabel.pack() # topLabel is Label