Im currently trying to change an image in a tkinter label widget by using a binding to the return key. After pressing the return key I would like the image to change to "im2", then wait for 2 seconds and change again to "im3". The code I use so far is:
window = tk.Tk()
window.title("Testwindow")
window.geometry("800x800")
window.configure(background='grey')
# images
im1_path = "im1.gif"
im2_path = "im2.gif"
im3_path = "im3.gif"
im1 = ImageTk.PhotoImage(Image.open(im1_path))
im2 = ImageTk.PhotoImage(Image.open(im2_path))
im3 = ImageTk.PhotoImage(Image.open(im3_path))
panel = tk.Label(window, image = im1)
panel.pack(side = "bottom", fill = "both", expand = "yes")
def callback(e):
panel.configure(image = im2)
panel.image = im2
time.sleep(2)
panel.configure(image = im3)
panel.image = im3
window.bind("<Return>", callback)
window.mainloop()
But instead of changing the image twice it is only changed once to "im3" 2 seconds after pressing return, so somehow the first change is not displayed. Does anyone know why?