Remove/Replace Tkinter Widget from Frame 
Author Message
 Remove/Replace Tkinter Widget from Frame

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

http://www.*-*-*.com/



Fri, 14 Jun 2002 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

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

2. Removing widgets from frames, why frames don't resize to 0x0

3. Tkinter: How to remove stacking order of a widget in grid manager

4. Tkinter: creating a scrolling canvas that contains widows (Frame widgets)

5. Tkinter:Changing widgets master Frame

6. pyxml minidom: I can remove and append, but not replace

7. another tkinter widget request: an athena stripchart widget.

8. remove title bar from frame?

9. removing "close" button in Tkinter

10. TkInter: class Grid missing remove?

11. tkerror command should be removed from Tkinter.py

12. Tkinter and frame resizing question

 

 
Powered by phpBB® Forum Software