| |||||||||||
| |||||||||||
Tcl/Tk - updating your display while tasks are running
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 {} {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 08:53:33) Associated topics are indexed under T242 - Tcl/Tk - More on ExpectT221 - Tcl/Tk - Menus T223 - Tcl/Tk - Textish Widgets
Some other Articles
FSB leaves its members feeling like mushroomsSome new C programming examples - files, structs, unions etc Decisions - small ones, or big ones? Shopping for Christmas and looking forward Tcl/Tk - updating your display while tasks are running Using Tcl/Tk resource files for flexible applications Making a variable dynamically visible in a Tcl/Tk GUI The Horse goes on and on Cliff Lift simulator- Lynton to Lynmouth - in Tcl/Tk fill and expand on Tcl/Tk pack command 1710 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||