Label in PyQt4 GUI not updating with every loop of FOR loop

The label gets updated all right, but the GUI isn’t redrawn before the end of your loop.

Here’s what you can do about it:

  • Move your long-running loop to a secondary thread, drawing the GUI is happening in the main thread.

  • Call app.processEvents() in your loop. This gives Qt the chance to process events and redraw the GUI.

  • Break up your loop and let it run using a QTimer with a timeout of 0.

Using a thread is the best option, but involves quite a bit more work than just calling processEvents. Doing it with a timer is the old fashioned way and is not recommanded anymore. (see the documentation)

Leave a Comment