Redrawing GUI while in a for loop

M

Marco Terzuoli

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?

Thanks
Marco
 
B

Brian Kelley

Marco said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top