Python sleep doesn't work right in a loop?
Steve Holden
steve at holdenweb.com
Wed Apr 6 16:17:56 EDT 2005
ritterhaus at yahoo.com wrote:
> Nope. Does't work. Running Python 2.3.4 on Debian, Linux kernel 2.6.
> This is actually test code for a larger project...
>
> # flash the selected wx.TextControl
>
> for flasher in range(4):
> self.textField.SetBackgroundColour(255, 0, 0)
> time.sleep(0.8)
> self.textField.SetBackgroundColour(255, 255, 223)
> time.sleep(0.8)
>
> Even when I add an explicit call to repaint the TextCtrl between each
> sleep, things appear to be 'queued' until after the loop is fnished.
> Very bizarre.
>
Not at all, but completely unrelated to your initial question.
You need to use a specific call before each sleep to tell wxPython to
update the display, since the sleep doesn't give control back to the
display subsystem. I think the call you need is app.Yield(), but the
docs will confirm that.
regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/
More information about the Python-list
mailing list