Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
time.sleep(...) problem
#1
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()
Reply
#2
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
Reply
#3
(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
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Need Help with Vehicle Routing Problem with Time Windows (VRPTW) in Python kasper321421312 1 502 Nov-10-2023, 08:19 PM
Last Post: snippsat
  Problem with module time and leap seconds Pedroski55 3 1,189 Oct-07-2022, 11:27 PM
Last Post: Pedroski55
  Use subprocess.Popen and time.sleep chucky831 2 1,890 Aug-11-2022, 07:53 PM
Last Post: carecavoador
  How to immediately kill and restart a thread while using a time.sleep() inside it? philipbergwerf 4 3,449 Feb-07-2022, 04:16 PM
Last Post: Gribouillis
  Time.sleep: stop appending item to the list if time is early quest 0 1,846 Apr-13-2021, 11:44 AM
Last Post: quest
  Can you end the Time.sleep function boier96 9 9,219 Jan-16-2021, 10:09 PM
Last Post: Serafim
  time.sleep mtnwinds 4 2,794 May-21-2020, 10:12 AM
Last Post: Larz60+
  kill thread or process asap, even during time.sleep nanok66 4 2,867 Apr-29-2020, 10:13 AM
Last Post: nanok66
  time.sleep works erratically, a bug in Python? stipcevic 2 3,817 Jan-21-2020, 09:38 PM
Last Post: Marbelous
  Adding Cosinus as utime.sleep variable Kreszy 0 1,694 Sep-19-2019, 04:27 PM
Last Post: Kreszy

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020