time.sleep(...) problem - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: time.sleep(...) problem (/thread-15703.html) |
time.sleep(...) problem - DPaul - Jan-28-2019 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() RE: time.sleep(...) problem - Larz60+ - Jan-28-2019 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 RE: time.sleep(...) problem - DPaul - Jan-28-2019 (Jan-28-2019, 11:27 AM)Larz60+ Wrote: you only have one widget, and are overwriting the contents on the second image display 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 RE: time.sleep(...) problem - Larz60+ - Jan-28-2019 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. |