Python Tkinter question
Thyme
TDSherer at go.com
Sun Jun 8 17:02:53 EDT 2003
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
More information about the Python-list
mailing list