Home>
import tkinter as tk
import PIL.Image
import PIL.ImageTk
from time import sleep
def openFile ():
    max_time = 5
    sec = 1
    for i in range (max_time):
        print ("{}". format (max_time --i))
        newImage = PIL.Image.open (fr "img \ {i + 1} .png"). Resize ((500,500))
        imageData = PIL.ImageTk.PhotoImage (newImage)
        lbl.configure (image = imageData)
        lbl.image = imageData
        sleep (sec)
    newImage = PIL.Image.open (r "img \ arrow0.png"). Resize ((500,500))
    imageData = PIL.ImageTk.PhotoImage (newImage)
    lbl.configure (image = imageData)
    lbl.image = imageData
    # lbl.configure (image = imageData)
root = tk.Tk ()
root.title ("test")
root.geometry ("1250x600")
btn = tk.Button (text = "START!", command = openFile)
newImaged1 = PIL.Image.open ("img \ start.jpg"). Resize ((640,480))
imageDatad1 = PIL.ImageTk.PhotoImage (newImaged1)
lbl = tk.Label (image = imageDatad1)
lbl.pack ()
btn.pack ()
tk.mainloop ()

With the function openFile, change i with a for statement to display 5 images {i + 1} .png for 1 second each.
Finally, I would like to display arrow0.png.
{i + 1} .png is not displayed.
I don't see what's in front of sleep, but I can't think of a good way.

I'm sorry for the basics,
I would like to know the cause and countermeasures.

  • Answer # 1

    lbl.update ()


    To

    lbl.image = imageData


    What happens if I put it right after?

Related articles