Skip to content Skip to sidebar Skip to footer

Using Time.sleep In Wxpython

Using time.sleep in my wxPython code just after re-positioning a bitmapbutton caused my button to go totally blank. Just a white space was left in the region where the button shoul

Solution 1:

time.sleep() blocks wx's mainloop and makes the GUI unresponsive for however long you've told it to sleep. There are several alternatives. You can use a wx.Timer or use threads (or similar). I think using a Timer makes more sense in your use case though.

Solution 2:

sleep is blocking, so execution is stuck in your position method for two seconds and is unable to return to the MainLoop to process other events, like painting your changes to the screen. After the two seconds are up the image is hidden, but was never drawn.

To get the effect you want you'll have to start a timer, and bind the timer to a handler which can show the StaticBitmap again.

By the way you can also call Show again rather than creating a new control, and it's parent should also be the panel, not the frame.

Post a Comment for "Using Time.sleep In Wxpython"