[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>&nbsp; Hi.&nbsp; Here is some code..</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>var =3D IntVar()</DIV>
<DIV>&nbsp;</DIV>
<DIV>##def die(x):<BR>##&nbsp;&nbsp;&nbsp; print =
'dead'<BR>##&nbsp;&nbsp;&nbsp;=20
print x</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;&nbsp; <BR>root =3D Tk()</DIV>
<DIV>&nbsp;</DIV>
<DIV>for text, value in [('Pathetic', 100), ('Good', 60), ('Fun', 40),=20
('Stupid', 15)]:<BR>&nbsp;&nbsp;&nbsp; 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>##&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;=20
lambda x=3Dx:die(x))]<BR>var.set(60)</DIV>
<DIV>&nbsp;</DIV>
<DIV>mainloop()<BR></DIV>
<DIV>&nbsp; I don't know why I get this error</DIV>
<DIV>&nbsp;</DIV>
<DIV>Traceback (most recent call last):<BR>&nbsp; File=20
"c:\python20\pythonwin\pywin\framework\scriptutils.py", line 301, in=20
RunScript<BR>&nbsp;&nbsp;&nbsp; exec codeObject in =
__main__.__dict__<BR>&nbsp;=20
File "C:\WINDOWS\Profiles\Glen\My Documents\Script1.py", line 4, in=20
?<BR>&nbsp;&nbsp;&nbsp; var =3D IntVar()<BR>&nbsp; File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 231, in =
__init__<BR>&nbsp;&nbsp;&nbsp;=20
Variable.__init__(self, master)<BR>&nbsp; File=20
"c:\python20\lib\lib-tk\Tkinter.py", line 172, in =
__init__<BR>&nbsp;&nbsp;&nbsp;=20
self._tk =3D master.tk<BR>AttributeError: 'None' object has no attribute =

'tk'<BR>&gt;&gt;&gt; Exception exceptions.AttributeError: "'IntVar' =
instance has=20
no attribute '_tk'" in &lt;method Variable.__del__ of IntVar instance at =

014E6DBC&gt; ignored<BR></DIV>
<DIV>&nbsp; Upon execution.&nbsp; It is almost verbatim from J Grayson's =

book.&nbsp; 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>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0009_01C0945A.47551660--