[PyQt] pyqt4 problem with label.setText timing within loops

Dan Cherry dan.s.cherry at gmail.com
Tue Feb 16 05:12:47 GMT 2010

I'm trying to run a simple 'for' loop to execute some external programs 
(ripping tracks with cdparanoia/lame, but I've stripped the problem down 
to bare essentials that demonstrate the problem).

Each loop should update a gui label with the current loop number.  The
setText statement is within the 'for' loop, but the gui doesn't get
updated until the loop is either completed or several iterations into
the complete loop.  The loop works, but the updates to the  label do not.

The Gui was created with QTDesigner, and I'm using python 2.6.4 on
Ubuntu 9.10.

The statements that are crucial follow below, and I've attached the two
py files if you care to see the full code.

Any suggestions for getting the label.setText statements to update the 
gui with each loop iteration, would be appreciated.

Dan Cherry

     def runloop(self):
         self.ui.label.setText('Begin Loop') ## <--doesn't update before 

         for i in range(1,6):
             self.ui.label.setText('loop %s' % i) ## <--doesn't update 
for each loop - but does update after the loop completes
             rval = self.loop(i)

     def loop(self, loop_no):
         print loop_no  ## <--the print statements display properly as 
the loop progresses

-------------- next part --------------
A non-text attachment was scrubbed...
Name: settextgui.py
Type: text/x-python
Size: 1833 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100216/906dd9ae/attachment-0002.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: settext-test.py
Type: text/x-python
Size: 882 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100216/906dd9ae/attachment-0003.py>

More information about the PyQt mailing list