954,190 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Python Sleep Function:

Hello:

I am trying to use the Python Sleep Function via import time; I get results but not the results I am looking for.

What I am trying to do is rather simple and only for visual effect in a Python GUI: Display GIF --> Sleep (pause) 5-seconds --> Display next GUI --> Repeat. Such as:

<strong>.</strong>
<strong>.</strong>
<strong>.</strong>
 
image3 = "pic1.GIF"
photo3 = PhotoImage(file=image3)
 
time.sleep(5)
 
image4 = "pic2.GIF"
photo4 = PhotoImage(file=image4)
 
<strong>.</strong>
<strong>.</strong>
<strong>.</strong>



What seems to happen is that I do note a pause, in this case roughly 5-seconds, but it happensbefore the GUI appears at all upon the screen; the canvas should display, then 1-by-1 each GIF should appear 5-seconds apart. Instead the pause occurs approximately 5-seconds after I initiate "RUN" and the entire thing is rendered without pause between GIFs

Any, hints, ideas, or direction would be greatly appreciated.

[** Using Dr.Python]


regards,
sharky_machine

mattyd
Posting Maven
2,607 posts since Oct 2006
Reputation Points: 105
Solved Threads: 1
 

Hi!

You are using Tkinter, right? Try this: after the time.sleep(), update the GUI with e.g. root.update() (if root is your main window).
I'm not sure if other GUI's need this too.

Regards, mawe

mawe
Junior Poster
133 posts since Sep 2005
Reputation Points: 19
Solved Threads: 58
 
Hi! You are using Tkinter, right? Try this: after the time.sleep(), update the GUI with e.g. root.update() (if root is your main window). I'm not sure if other GUI's need this too. Regards, mawe

Thank-you for your help-- this worked great. ;)

sharky_machine

mattyd
Posting Maven
2,607 posts since Oct 2006
Reputation Points: 105
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You