我正在编写我的第一个 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"
这不是属性吗?