[Tutor] Tkinter - Destroying windows, destroying widgets
Sun, 4 Feb 2001 08:13:14 -0500
One of the advantages of using classes to deal with TKinter is that you
in effect get 'global' variables for free. If within a class you do
self.second = Toplevel(root)
then your destroy function can say
since 'self' is always passed as the first argument to all methods
(functions within a class).
On Sun, Feb 04, 2001 at 11:28:31PM +1100, Glen Wheeler wrote:
> 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'
> root = Tk()
> l = Label(root, text='hi im root').pack()
> second = Toplevel(root)
> b = Button(root, text='yo', command=die).pack()
> 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.
"Good intentions will always be pleaded for every assumption of
authority. It is hardly too strong to say that the constitution was
made to guard the people against the dangers of good intentions. There
are men in all ages who mean to govern well, but they mean to govern.
They promise to be good masters, but they mean to be masters."
-- Noah Webster
Rick Pasotto email: firstname.lastname@example.org