From: Alex Fenton Date: 2007-09-24T18:40:04+09:00 Subject: Re: how to use Ruby / Tk to display a text message status box SpringFlowers AutumnMoon wrote: > how can we pop up a Tk window to display the temporary results of a > program? The normal way to do this is in a GUI program is to use Threads ... > right now i have: > ... > Tk.mainloop > > [and my program] > > but the program won't run until i close the Tk window generated. When you call "mainloop", you're telling Tk (and other GUIs, too) to wait for the user to do something (eg click a button). This is sometimes called an "event loop". As the "loop" name suggests, the program stops at this point and nothing further will be run until the GUI is ended. To run other tasks (such as your calculation) concurrently with the event loop, start those other tasks in a ruby Thread alongside the GUI code. Then, if you want to display intermediate results from that task in the GUI, pass messages between the task thread to the main GUI thread. Again, there's numerous different ways to do this. I haven't used Ruby Tk so I'm not sure if it's an issue, but in many other toolkits, the non-GUI threads may starved of execution time - ie the GUI event loop hogs the scheduler. So if you are finding your background task is not progressing, you may need to set up a timed event in the Tk code that passes control among the Threads (eg calling Thread.pass) hth alex