Remove/Replace Tkinter Widget from Frame

Colleen & Brian Smith greybria at direct.ca
Mon Dec 27 12:50:04 EST 1999


Hi gang, I'm back!
The buttons are now working after the image is loaded. Thanks for the
various suggestions. I'm not sure which one actually fixed it as many had no
trouble with the code before. This is what it looks like now:

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

class Application(Frame):

    def LoadPic(self):
        self.picname=askopenfilename(filetypes=[("JPEG", "*.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):
       delete(self.display)
       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()

What I want to do is on the UNLOAD button, remove the image and allow a new
one to be loaded, without
creating two images.  I've tried various combinations of self.pic.destroy()
etc.  What is the "proper" way
to remove the image and allow a new one to be loaded?

Thanks.

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





More information about the Python-list mailing list