Python Forum

Full Version: time.sleep(...) problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is the idea :
- I show a picture via Tkinter : no problem
- I want the program to wait for e.g. 3 seconds
- and then show the next picture, (and so on like a slide show) I have only 2 pics in this code extract.
Problem: I can show the first picture,
but when i add the sleep funtion and the second picture,
it does not show the first pic any more: just sleeps and shows the second picture? Help?
- I want the first picture to keep showing for 3 secs and then show the next.
img = ImageTk.PhotoImage(PIL.Image.open(p / 'pic.jpeg'))
fotoLabel = Label(tk, bg = 'black', image = img) 
fotoLabel.pack(fill = "both", expand = "yes")

time.sleep(3)

img = ImageTk.PhotoImage(PIL.Image.open(p / 'b.jpg'))
fotoLabel.configure(image = img)

tk.mainloop()
you only have one widget, and are overwriting the contents on the second image display
create a second widget (I guess you're using Label, so 2nd Label) and load second image there
(Jan-28-2019, 11:27 AM)Larz60+ Wrote: [ -> ]you only have one widget, and are overwriting the contents on the second image display
create a second widget (I guess you're using Label, so 2nd Label) and load second image there

The idea is that the second image replaces the first one after a while.
I can create a second widget in the same spot, but should i 'destroy()' the first one?

thx,
Paul
If they are the same size, it's probably OK to just overwrite, but I say 'probably'
Since size is one of the optional variables of PhotoImage, I expect it's always a good idea to clear the label before writing new image.