PyQt GUI change Button-text process time

249 Views Asked by At

I don't understand much about Gui action execution order etc., but my Problem is very simple: I have a Code that looks like this:

button.setText('text')
do sth
time.sleep(1)
do sth else

Somehow the script always fails to set the text before the timeout, and therefore the timeout also breaks this action and the text appears only after the timeout. How can I tell this line of code to finish execution dispite the time.sleep()? Or do i have to introduce an if-statement, only to wait until the button has set its text (is there a better way)

Thanks

1

There are 1 best solutions below

1
On BEST ANSWER

GUI applications typically use some event loop, which is responsible for actually painting your widgets, etc.

You can not block this event loop with a sleep, or your application will stop responding.

Instead, in the case of Qt, use a QTimer to invoke whatever you want to do asynchronously.