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)


You have a basic misunderstanding of how such a GUI works. A Qt GUI has to run in an event loop of its own. Your loop runs instead, and the GUI can't do its work between the executions of your loop. That is, while your for loop is running the GUI code doesn't get CPU time and won't update.

You can set up a timer with an event, and execute your code in handlers of this event a set amount of time - this will solve your problem.


Or you can just call repaint() it update the GUI instantly.