[Tutor] Raiobutton question
Glen Wheeler
wheelege@tsn.cc
Sun, 11 Feb 2001 18:41:43 +1100
This is a multi-part message in MIME format.
------=_NextPart_000_0009_01C0945A.47551660
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Hi. Here is some code..
from Tkinter import *
var =3D IntVar()
##def die(x):
## print 'dead'
## print x
=20
root =3D Tk()
for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40), =
('Stupid', 15)]:
Radiobutton(root, text=3Dtext, value=3Dvalue, =
variable=3Dvar).pack(anchor=3DW)
##b =3D Button(root, text=3D'lets go', command=3D
## lambda x=3Dx:die(x))]
var.set(60)
mainloop()
I don't know why I get this error
Traceback (most recent call last):
File "c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, =
in RunScript
exec codeObject in __main__.__dict__
File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in ?
var =3D IntVar()
File "c:\python20\lib\lib-tk\Tkinter.py", line 231, in __init__
Variable.__init__(self, master)
File "c:\python20\lib\lib-tk\Tkinter.py", line 172, in __init__
self._tk =3D master.tk
AttributeError: 'None' object has no attribute 'tk'
>>> Exception exceptions.AttributeError: "'IntVar' instance has no =
attribute '_tk'" in <method Variable.__del__ of IntVar instance at =
014E6DBC> ignored
Upon execution. It is almost verbatim from J Grayson's book. Also, =
I'd like to know how to fix errors such as these if they come up in the =
future - this is the first time I have seen one like this.
Thanks,
Glen.
------=_NextPart_000_0009_01C0945A.47551660
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV> Hi. Here is some code..</DIV>
<DIV> </DIV>
<DIV><BR>from Tkinter import *</DIV>
<DIV> </DIV>
<DIV>var =3D IntVar()</DIV>
<DIV> </DIV>
<DIV>##def die(x):<BR>## print =
'dead'<BR>## =20
print x</DIV>
<DIV> </DIV>
<DIV> <BR>root =3D Tk()</DIV>
<DIV> </DIV>
<DIV>for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),=20
('Stupid', 15)]:<BR> Radiobutton(root, text=3Dtext, =
value=3Dvalue,=20
variable=3Dvar).pack(anchor=3DW)<BR>##b =3D Button(root, text=3D'lets =
go',=20
command=3D<BR>## &nb=
sp;=20
lambda x=3Dx:die(x))]<BR>var.set(60)</DIV>
<DIV> </DIV>
<DIV>mainloop()<BR></DIV>
<DIV> I don't know why I get this error</DIV>
<DIV> </DIV>
<DIV>Traceback (most recent call last):<BR> File=20
"c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, in=20
RunScript<BR> exec codeObject in =
__main__.__dict__<BR> =20
File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in=20
?<BR> var =3D IntVar()<BR> File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 231, in =
__init__<BR> =20
Variable.__init__(self, master)<BR> File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 172, in =
__init__<BR> =20
self._tk =3D master.tk<BR>AttributeError: 'None' object has no attribute =
'tk'<BR>>>> Exception exceptions.AttributeError: "'IntVar' =
instance has=20
no attribute '_tk'" in <method Variable.__del__ of IntVar instance at =
014E6DBC> ignored<BR></DIV>
<DIV> Upon execution. It is almost verbatim from J Grayson's =
book. Also, I'd like to know how to fix errors such as these if =
they come=20
up in the future - this is the first time I have seen one like =
this.</DIV>
<DIV> </DIV>
<DIV> Thanks,</DIV>
<DIV> Glen.</DIV></BODY></HTML>
------=_NextPart_000_0009_01C0945A.47551660--