Need help changing image in a toga.imageview #1279
-
I just started toga, so I am a newbie.. So I have a program in which I need to change the image when a button is clicked, so I tried various things but none seemed to work.. Can someone please help? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Set the
|
Beta Was this translation helpful? Give feedback.
-
GUIs only update when they're in the "redraw" portion of their application event loop. An event handler is executed as part of the same event loop, so if you're currently in a handler, the The call to The fix for both of these problems is the same - you need to instruct the handler to release control to the event loop. If you replace I can't comment on why the "same code" works with Qt - I know almost nothing about the internals of Qt. I can only assume they have some framework-level handling that runs event handlers in a separate thread, or forces a redraw on certain changes. |
Beta Was this translation helpful? Give feedback.
GUIs only update when they're in the "redraw" portion of their application event loop. An event handler is executed as part of the same event loop, so if you're currently in a handler, the
redraw
portion of the event loop isn't being processed. As a result, any changes to the image won't be redrawn until you get to the end of the handler, at which point the value of the image at the end of the handler will be the "current" image, and it will be the image that is drawn.The call to
sleep()
is also problematic. The handler will be blocking the event loop until the entire handler method has finished; by callingsleep()
, the handler will take multiple seconds to complete, during which time th…