I have opened an image using the PhotoImage method of ImageTk
How do I close the image.

This is the scenario is I am using it in. I have 2 buttons, one each to open an image from disk & image from url. When I open either of them the image is displayed. But when I open a new image, the old image remains on the screen & the new image is displayed below it.

How do I close the old image so that only the new image is seen.

Code snippet of for opening the images:

def file_open(self):
                filename =askopenfilename(filetypes=imageTypes)
                image1 = ImageTk.PhotoImage(Image.open(filename))
                panel1 = Label(self, image=image1)
                panel1.pack(side='top', fill='both', expand='yes')
                panel1.image = image1
                
        def openurl(self):
                
                url= tkSimpleDialog.askstring("Open URL","Enter URL")
                file =urllib.urlopen(url)
                im = cStringIO.StringIO(file.read()) 
                img = Image.open(im)
                image1 = ImageTk.PhotoImage(img)
                panel1 = Label(self, image=image1)
                panel1.pack(side='top', fill='both', expand='yes')
                panel1.image = image1

If you put the image on a canvas, you can delete it with something like canvas.delete(image)

vegaseat,
thank you! I used the canvas & I'm able to get what I wanted.
Your quick answers have been a gr8 help for newbies like me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.