0

I want to change the image of the one labels in time with 2 other images but it immideatly skipts to the last one. Any suggestions?

I have tried using time.sleep incase it might happen so fast that before i could notice but it didnt work.

import tkinter
from tkinter import *
from PIL import Image , ImageTk
import time

window = tkinter.Tk()

window.geometry("500x500")
window.title("Pomodoro Timer")

window.image_1 = ImageTk.PhotoImage(Image.open("1.jpg"))
window.image_2 = ImageTk.PhotoImage(Image.open("2.jpg"))
window.image_3 = ImageTk.PhotoImage(Image.open("3.jpg"))

lbl_1 = tkinter.Label(window, image=window.image_1)
lbl_1.place(x=150,y=100)

lbl_2 = tkinter.Label(window, image=window.image_2)
lbl_2.place(x=200,y=100)

def display_numbers():
    lbl_1
    lbl_2
display_numbers()

def clicked():
    i=1
    while i<3:

        if i==1:
            lbl_1.configure(image=window.image_2)
            time.sleep(0.91)


            i += 1
        elif i==2:
            lbl_1.configure(image=window.image_3)
            time.sleep(0.91)
            i += 1

btn = tkinter.Button(window, text="Start", command=clicked)    
btn.place(x=200,y=450,width=100)

window.mainloop()
Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
TolgaT
  • 175
  • 2
  • 7
  • 4
    Its a terrible idea to use sleep with a gui library. It will freeze up the whole application during the sleep. Instead you can use the after method of the widgets to implement the delay. You will need to restructure the code though to implement the images changes across multiple function calls (one after each delay). – Paul Rooney Oct 02 '19 at 00:43
  • First you have to understand [Event-driven programming](https://stackoverflow.com/a/9343402/7414759) – stovfl Oct 02 '19 at 07:56

0 Answers0