Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python won't recognise attribute

I am coding my first GUI application to find products for a company.

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()

When I run this, it comes up with the error message:

AttributeError: Button instance has no attribute 'text'

But in the creation of 'fire' it says

text="fire"

Isn't this an attribute?

like image 619
cjm Avatar asked Jun 30 '26 17:06

cjm


1 Answers

The Tkinter module is a little old-skool; the text value can be accessed via an item lookup:

relStatus.set(fire['text'])

See the Setting Options section of the Tkinter documentation.

like image 160
Martijn Pieters Avatar answered Jul 02 '26 05:07

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!