Bottom Page

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()

Quote
#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
Quote
#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
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Why does time.sleep(wait) add time in python3 ? gerardg 4 517 Apr-28-2019, 06:26 PM
Last Post: gerardg
  How to achieve close to 1ms time.sleep kwekey 1 224 Mar-25-2019, 02:52 AM
Last Post: Larz60+
  If error sleep and then try again from there CaptainCsaba 2 228 Mar-01-2019, 06:28 AM
Last Post: CaptainCsaba
  time.time wont return a useable number Nyscersul 4 466 Nov-15-2018, 03:08 PM
Last Post: Nyscersul
  'Time Limit Exceeded' Problem bkpee3 2 606 Nov-14-2018, 03:51 AM
Last Post: bkpee3
  Multi-processing - problem with running multiple *.py files at the same time Antonio 5 637 Sep-12-2018, 01:08 PM
Last Post: volcano63
  Alternative for time.sleep()? Atkion 1 2,344 Jan-15-2018, 10:25 PM
Last Post: metulburr
  Getting error in finding time.time() value in python Lakshana 1 692 Jan-11-2018, 07:07 AM
Last Post: wavic
  time range midnight problem PickyBiker 9 4,780 Dec-15-2016, 12:09 AM
Last Post: Ofnuts

Forum Jump:


Users browsing this thread: 1 Guest(s)