Python Tkinter question

DavidW Blaschke dwblas at yahoo.com
Mon Jun 9 04:29:45 CEST 2003


An Entry widget uses a textvariable, a Label takes
text, not a textvariable.  So you would want to write:

con1 = "Quick Question"
...
self.label1 = Label(master, text=con1)

Good Luck
D.W.

> 
> --- In python-list at yahoogroups.com, TDSherer at g...
> (Thyme) wrote:
> > I've hit a bump learning to use Tkinter. Nothing
> I've found on line
> > has helped me nail down the problem. Any insights
> would be welcome.
> > 
> > This is something very easy, actually - I'm trying
> to use the 
> feature
> > a label is assigned a variable so that it can be
> automatically
> > updated. I followed the syntax I found in a
> Tkinter PDF on line and
> > another online doc I found.
> > 
> > Here is some code:
> > 
> > # File: testx.py
> > from Tkinter import *
> > 
> > con1 = StringVar("Quick Question!")
> > 
> > class App:
> > 	def __init__(self, master):
> > 		frame = Frame(master)
> > 		frame.pack()
> > 		self.label1 = Label(master, textvariable=con1)
> > 		self.label1.pack()
> > 
> > root = Tk()
> > app = App(root)
> > root.mainloop()
> > 
> > When I run this, I get the following error:
> > 
> > C:\python\SizeOf>python testx.py
> > Traceback (most recent call last):
> >   File "testx.py", line 4, in ?
> >     con1 = StringVar("Quick Question!")
> >   File "C:Python22\lib\lib-tk\Tkinter.py", line
> 217, in __init__
> >     Variable.__init__(self, master)
> >   File "C:Python22\lib\lib-tk\Tkinter.py", line
> 171, in __init__
> >     self._tk = master.tk
> > AttributeError: 'str' object has not attribute
> 'tk'
> > Exception exceptions.AttributeError: "StringVar
> instance has no
> > attribute '_tk'" in <bound method
> StringVar.__del__ of
> > <Tkinter.StringVar instance at 0x008B2D40>>
> ignored
> > -- 
> >
> http://mail.python.org/mailman/listinfo/python-list
> 


__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com





More information about the Python-list mailing list