| |||
Handling long running processes in tk Posted by rgm1960 (rgm1960), 19 September 2005 Hi,I am creating a gui for a scientific app that has a couple of long running processes. For instance when I push a button "Run", the callback proc of "Run" calls another function (loaded during initialization by doing "load my.dll RunCmd") This function takes about 60sec or so to return and during this whole time the button "Run" stays pushed (active). How do I get the button to be in a normal state immediately after its callback is invoked and instead have my cursor turn to, say an hour glass until the function returns to the tcl script? Any insights will be appreciated. Thanks. Regards, Raghu Posted by admin (Graham Ellis), 20 September 2005 You're looking for the update idletasks command ... and we've an example of it in use in a live application at http://www.wellho.net/resources/ex.php4?item=t221/mb3In normal running, Tk only updates the display when it has nothing else to do, for the very good reason that you don't want to see you GUI growing slowly as you first build it up, nor see a whole long series of incremental changes flash by you when you take some action that results in (for example) a window being resized. In cases where you make a selection on the GUI that's going to tie the process up for a while, though, you want to be able to change this behaviour and give an immediate feedback to the user that, yes, his button press was noted and is being acted on. So add an update idletasks command near the start of the long-to-run process, just after you have made the GUI command calls to alter the display; this forces all pending GUI changes to be actioned You may want to go further; if you want to give some sort of progress bar for your long rinning process ... let's say it's of the form of a loop that runs 3 times (like my ping example), you could updatethe display every time through the loop. But be very careful that you don't put the update within a tight loop - it would be very easy to slow down the process as a whole. This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
| |||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |