Stavrius Mtvs
Stavrius Mtvs

Reputation: 241

Destroy Image in Python Tkinter

My Question is how to destroy a image with a Button Click.

This is the image-upload.

img1 = PhotoImage(file="C:/Users/Stavr/Desktop/giphy.gif") w1 = Label(root, image=img1) w1.place(x = 360, y = 380)

This is the button

delete_image_Button=Button(root, text="delete image", command=delete_image_function)

And here the function

def delete_image_function():
    ???????????

Ok i thing the question is clear. Can someone help me to fill this code? Thanks ahead of time!!

Upvotes: 0

Views: 3136

Answers (1)

EHM
EHM

Reputation: 959

You could do something like this,

from tkinter import *

root=Tk()

img1=PhotoImage(file='firstimage.gif') #the image that is displayed first
img2=PhotoImage(file='secondimage.gif') #the second image that will appear when the first is destroyed

image_1 = Label(root, image=img1)
image_1.place(x = 100, y = 100)

def delete_image():
    image_1.destroy()
    image_2=Label(root,image=img2)
    image_2.place(x=0,y=0)

Button(root,text='Delete_image',command=lambda:delete_image()).place(x=200,y=200)
root.mainloop()

i hope this helps.

Upvotes: 1

Related Questions