Let me make two statements:
1. When you are popping up a new window from your program, the very last thing you want to see happen is for the window to gradually appear, with bits of it being resized as it comes on the screen - not only is such an operation irritating on the eye, but also it's burning up a lot of processor time in working and re-working the display which slows the whole operation down.
2. When you press on a button within a window, you're looking for near-instant feedback - gratification that the button press has indeed been accepted, and if your press starts a longer operation running on the computer, you're also hoping - I'm sure - to receive feedback while the job is happening. Maybe a progress bar, a moving graph, or something like that.
These two requirements are opposites.
In Tcl/Tk, the screen is automatically updated
just before the Tcl/Tk application goes into an event wait loop - in other words, the windows will pop up / be updated just prior to the point at which user input is once again accepted. This is very efficient in terms of display (as you would expect from a system that was written years ago, when computers were much less powerful) and usually pleasing on the eye.
On that small proportion of occasions that you want to have your display dynamically updated, you can add an
update idletasks command into your Tcl/Tk code at appropriate times. This command causes all queued screen updates to be performed, even if the user is not about to be prompted for further input straight thereafter.
Here's an example of what I mean.
Initial display:
When I click on the "check status" button it runs a ping test three times, at intervals of one second, to test out the connection. If
and only if I use
update idletasks, the following will be displayed while this ping test is going on:
and when the task has completed, you'll get a full report (in all cases, as the screen is automatically updated prior to being available for further user inputs)
Here's a snippet of code - the proc that's run when the "check status" button is pressed. Full code on our web site
here
proc pingit {} {
global currenthost
.result config -text "running test ... please wait"
update idletasks
# If you comment the previous line out
# the user is left wondering what is going on!
catch {exec ping -c 3 $currenthost} result
# Note the use of catch to recover exec results
.result config -text $result
}
You may have guessed that I just completed a
public Tk course - inspiration to write up in more details and for "Joe Public" many of the issues that we cover on the course. GUI design - topics like
fill and
expand,
sticky news, canvas scaling and
update idletasks are perfect to teach and learn in the classroom, but are very hard to pick up from the books. Our Tk course is always a very effective one and students leave having really gained a huge amount that would be so hard to appreciate fully through self-study!
(written 2007-12-16)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T242 - Tcl/Tk - More on Expect [435] Expect for Windows - (2005-09-04)
[1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
[1411] Buffering of inputs to expect, and match order - (2007-10-27)
[1531] Expecting a item from a list of possibles - (2008-02-04)
[2475] Quick easy and dangerous - automated logins via Tcl / Expect - (2009-10-24)
[3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)
[3448] Checking all the systems on a subnet, using Expect and Tk - (2011-09-18)
T223 - Tcl/Tk - Textish Widgets [596] The magic of -textvariable - (2006-02-08)
T221 - Tcl/Tk - MenusG998 - Well House Consultants - Newsletter Highlighted Box [1011] Well House Manor and Beechfield House, Hotels, Melksham - (2006-12-29)
[1068] ls -l report, Linux / Unix - types and permssions - (2007-02-06)
[1132] Well House Manor, Melksham, Art Gallery - (2007-04-02)
[1237] What proportion of our web traffic is robots? - (2007-06-19)
[1307] Troy, up state New York - (2007-08-17)
[1375] Python v Ruby - (2007-10-02)
[1521] Evening drive across the roof of Wiltshire - (2008-01-27)
[1621] Linux and Java Course in London - (2008-04-24)
[1629] A short introduction to our courses - (2008-05-03)
[1751] Public Training Course Dates until July 2009 - (2008-08-13)
[1843] How many cups of coffee? - (2008-10-17)
[1967] LinkedIn - Thrice Asked, and joined. - (2008-12-30)
[2050] Why the Pony Tail? - (2009-02-21)
[2125] We have lost a regular business guest - (2009-04-10)
[2222] A (biased?) comparison of PHP courses in the UK - (2009-06-07)
[2385] Reading all our recent news from a single source - (2009-08-29)
[2400] Are you wanting to learn PHP? - (2009-09-08)
[2520] Global and Enable - two misused words! - (2009-11-30)
[3168] Web Sites - Subject to Advertising Standards from 1st March - check your sites - (2011-02-13)
Some other Articles
FSB leaves its members feeling like mushroomsSome new C programming examples - files, structs, unions etcDecisions - small ones, or big ones?Shopping for Christmas and looking forwardTcl/Tk - updating your display while tasks are runningUsing Tcl/Tk resource files for flexible applicationsMaking a variable dynamically visible in a Tcl/Tk GUIThe Horse goes on and onCliff Lift simulator- Lynton to Lynmouth - in Tcl/Tkfill and expand on Tcl/Tk pack command