??? Tkinter destroy() - Remove a widget from a frame.

Randall Hopper aa8vb at yahoo.com
Wed Dec 29 13:08:07 EST 1999


Colleen & Brian Smith:
 |What is the proper way to destroy() the "display" widget (which is actually
 |a Label descendent -- taken from the Viewer.py script that comes as a demo
 |for the Python Imaging Library)  in the code below, so that I can recreate
 |it and load a new image in the UnloadPic method?
...
 |from viewer import UI
...
 |from tkFileDialog import *
 |
 |class Application(Frame):
...
 |        self.display = UI(self,self.pic).pack(side=TOP)
...
 |        self.display.destroy() # does not work

Yep, I've done that.  :-)  You're not doing what you think you're doing.
Notice:

     > python
     >>> from Tkinter import *
     >>> root = Tk()
     >>> btn1 = Button( text="1" )   
     >>> btn1.pack()
     >>> hmmm = Button( text="2" ).pack()
     >>> print btn1
     .270148832
     >>> print hmmm
     None

hmmm is not the second Button you created.  It's not set to what Button()
returns, but rather what Button.pack() returns.  This is self.display in
your case.

Are you getting an error that looks something like this?:

     AttributeError: 'None' object has no attribute 'destroy'

That's what's going on.

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list