faqts : Computers : Programming : Languages : Python : Tkinter

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

10 of 13 people (77%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I change the text on a label? When I use the variabletext=whatever thing, the label wont show up.

Jul 22nd, 2000 20:22
unknown unknown, richard_chamberlain, Charles G Waldman


from Tkinter import *
root=Tk()
myString=StringVar()
Label(root,textvariable=myString).pack()
myString.set("Well, eh, how about a little red Leicester.")
def changeLabel():
    myString.set("I'm, a-fraid we're fresh out of red Leicester, sir. ")
Button(root,text='Click Me',command=changeLabel).pack()
root.mainloop()
I presume where you're going wrong is you are not creating an instance 
of StringVar and setting (or getting) the variable through that.
----
See http://www.secretlabs.com/library/tkinter/introduction/index.htm
for lots of useful tkinter information.