Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python赢得了';无法识别属性_Python_Oop_User Interface_Tkinter - Fatal编程技术网

Python赢得了';无法识别属性

Python赢得了';无法识别属性,python,oop,user-interface,tkinter,Python,Oop,User Interface,Tkinter,我正在编写我的第一个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("700x

我正在编写我的第一个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"

这不是一个属性吗?

Tkinter模块有点旧了;
文本
值可通过项目查找访问:

relStatus.set(fire['text'])

请参阅Tkinter文档的第页。

谢谢,我自己永远不会得到它:)
topLabel = Label(app, textvariable = labelText, height = 5).pack()  # so topLabel is None

topLabel = Label(app, textvariable = labelText, height = 5)
topLabel.pack() # topLabel is Label