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

Colleen & Brian Smith greybria at direct.ca
Tue Dec 28 20:12:33 EST 1999


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?

Thanks in advance.
--------------------------------------------------------------------

from Tkinter import *
import Image, ImageTk
from viewer import UI
from tkFileDialog import *

class Application(Frame):

    def LoadPic(self):
        self.picname=askopenfilename(filetypes=[("Image Files",
"*.bmp;*.gif;*.jpg")])
        self.pic = Image.open(self.picname)
        self.pic.thumbnail((400,300))
        self.display = UI(self,self.pic).pack(side=TOP)
        self.LOAD["state"]="disabled"
        self.UNLOAD["state"]="normal"

    def UnloadPic(self):
        self.display.destroy() # does not work
        self.LOAD["state"]="normal"
        self.UNLOAD["state"]="disabled"

    def createWidgets(self):
        self.QUIT = Button()
        self.QUIT["text"] = "QUIT"
        self.QUIT["fg"] = "red"
        self.QUIT["command"] = self.quit
        self.QUIT.pack(side=RIGHT)

        self.LOAD = Button()
        self.LOAD ["text"] = "Load"
        self.LOAD ["command"] = self.LoadPic
        self.LOAD.pack(side=LEFT)

        self.UNLOAD = Button()
        self.UNLOAD ["text"] = "Unload"
        self.UNLOAD ["command"] = self.UnloadPic
        self.UNLOAD ["state"] = "disabled"
        self.UNLOAD.pack(side=TOP)

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.pack()
        self.createWidgets()

app = Application()
app.mainloop()


--
Brian Smith
greybria at direct.ca
http://mypage.direct.ca/g/greybria





More information about the Python-list mailing list