I have a program where an image on a Tkinter GUI is replaced on a button click. I attached a function to the button where the original label is destroyed and replaced with a new one. Then I pack the new image using the new label. However, the image is not shown. It seems that I have to call mainloop()
in the new function as well. Even that doesn't solve it.
def update():
global imglabel
imglabel.destroy()
Img = ImageTk.PhotoImage(Image.open("img7.bmp"))
imglabel = Label(image=Img)
imglabel.pack()
root = Tk()
button1 = Button(root, text="Update", command=update)
button1.pack()
Img = ImageTk.PhotoImage(Image.open("img27.bmp"))
imglabel = Label(image=Img)
imglabel.pack()
root.mainloop()