Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Handling long running processes in tk

Posted by rgm1960 (rgm1960), 19 September 2005
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.

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

In 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 and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho