[Tutor] Tkinter - Destroying windows, destroying widgets

Glen Wheeler wheelege@tsn.cc
Sun, 4 Feb 2001 23:28:31 +1100


This is a multi-part message in MIME format.

------=_NextPart_000_0015_01C08F02.2F800700
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

  Hey all,

  I was just writing up a little tkinter app (a game, actually) and I =
have hit a wall.  My predicament, is that I want to destroy an object =
(right word?) but I want to do it in a function...for example in this =
code :

from Tkinter import *

def die():
    l.destroy() ## here is the problem - root.l.destroy() does not work =
either - I think since variables are local in functions it doesn't have =
any clue as to the existence of the label "l"
    print 'yo'    =20
    raw_input("hi")

root =3D Tk()
root.title('jim')
l =3D Label(root, text=3D'hi im root').pack()
second =3D Toplevel(root)
b =3D Button(root, text=3D'yo', command=3Ddie).pack()

mainloop()

  No matter how hard I try I cannot kill the label "l" using the button, =
and have it do other things as well.  Say I wanted to destroy a widget =
in a different window??  That label is in the same toplevel.  I just =
know there is a way to say something akin to "In the widget 'root' is a =
widget 'l' - kill it" but for the life of me I cannot find it.  You =
can't pass a widget as an argument using lambda, either - I tried tho :)
  I've looked in John Grayson's book and the python docs but I can't =
find anything.  Help!

  Thanks,
  Glen.

------=_NextPart_000_0015_01C08F02.2F800700
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; Hey all,</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; I was just writing up a little tkinter app (a game, =
actually) and I=20
have hit a wall.&nbsp; My predicament, is that I want to destroy an =
object=20
(right word?) but I want to do it in a function...for example in this =
code=20
:</DIV>
<DIV>&nbsp;</DIV>
<DIV>from Tkinter import *</DIV>
<DIV>&nbsp;</DIV>
<DIV>def die():<BR>&nbsp;&nbsp;&nbsp; l.destroy() ## here is the problem =
-=20
root.l.destroy() does not work either - I think since variables are =
local in=20
functions it doesn't have any clue as to the existence of the label=20
"l"<BR>&nbsp;&nbsp;&nbsp; print 'yo'&nbsp;&nbsp;&nbsp;&nbsp;=20
<BR>&nbsp;&nbsp;&nbsp; raw_input("hi")</DIV>
<DIV>&nbsp;</DIV>
<DIV>root =3D Tk()<BR>root.title('jim')<BR>l =3D Label(root, text=3D'hi =
im=20
root').pack()<BR>second =3D Toplevel(root)<BR>b =3D Button(root, =
text=3D'yo',=20
command=3Ddie).pack()</DIV>
<DIV>&nbsp;</DIV>
<DIV>mainloop()</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; No matter how hard I try I cannot kill the label "l" using =
the=20
button, and have it do other things as well.&nbsp; Say I wanted&nbsp;to =
destroy=20
a widget in a different window??&nbsp; That label is in the same =
toplevel.&nbsp;=20
I just know there is a way to say something akin to "In the widget =
'root' is a=20
widget 'l' - kill it" but for the life of me I cannot find it.&nbsp; You =
can't=20
pass a widget as an argument using lambda, either - I tried tho :)</DIV>
<DIV>&nbsp; I've looked in John Grayson's book and the python docs but I =
can't=20
find anything.&nbsp; Help!</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp; Thanks,</DIV>
<DIV>&nbsp; Glen.</DIV></BODY></HTML>

------=_NextPart_000_0015_01C08F02.2F800700--