Redrawing GUI while in a for loop

Brian Kelley bkelley at wi.mit.edu
Thu May 20 21:31:51 EDT 2004


Marco Terzuoli wrote:
> Hi,
> I am making a program which has got some GUI. I need a timer in it which
> performs some kind of operations. What I am doing now is something like
> 
> while 1:
>         sleep(1)
>         do_stuff()
> 
> But this way I cannot interact with the GUI since the program is only run
> within the while loop. Is there any way to solve the problem either with a
> function that temporarily passes control to the OS (something like DoEvents
> in Visual Basic) or with a timer instruction which regularly calls a
> function I define?

One of your best solutions is to use a worker thread.  What GUI toolkit 
are you using?   There are many examples available for most toolkits.

Most GUI's do support some form of message pushing like DoEvents, I 
believe Tkinter's mainloop can be called with an integer value to 
process a certain number of events, although this might be a bad memory 
on my part.

Brian


> 
> Thanks
> Marco




More information about the Python-list mailing list