Retiring, March 2020 - sorry, you have missed our final public course.
The Coronavirus situation has lead us to suspend public training - which was on the cards anyway, with no plans to resume
Please ask about private 'maintenance' training for Python, Tcl, Perl, PHP, Lua, etc
Happily continuing private consultancy / programming work
Keeping you Tkinter display up to date while monitoring
Have you ever updated a web page just to find that something changes and it needs to be updated again? Have you every tidied the kitchen just to find it messy again within a few minutes? Are there time when it's sensible to say "we'll leave that until ..."?
It's the same when you're programming a Graphic User Interface and changing the display. Multiple changes - perhaps dozens of them - are to be done in quick succession, and it's going to be inefficient (and distracting to the viewer) to see the changes flashing up with lots of intermediate resizes and colour changes. So graphic user interfaces buffer up the changes and apply them all at once - and by default, that application of the changes is when all the tasks to be done have been completed, all incoming events handled, and the program's about to go back into an idle state waiting for the next user event.
Most of the times, this approach is spot on. Changes are stored internally and applied, and the changing of the screen provides a very clear signal to the user that it's time to interact again. Mentally, it's spot on. But that's most of the time, and just occasionally you may want an intermediate update. Take for example a GUI that's monitoring an ongoing process; you'll want to update the display even if no user input is expected should the monitoring reveal something's changed. So you can force an update using update_idletasks
(that's the TkInter name) or update idletasks
(Tk). Here's an example of a Python / Tkinter program that uses this technique - it (a) does an update, (b) sleeps for 2 seconds and (c) does another update. With the update_idleatsks() I have used, the changes appear with a gap of 2 seconds between them; without that line, nothing happs for 2 seconds after pressing the button then both changes appear.
import Tkinter as tk
top = tk.Tk()
# make first change
oldText = L.cget("text")
newText = oldText + '\nfirst change'
# wait 2 seconds
# make second change
newText += '\nsecond change'
B = tk.Button(top, text ="Change text", command = addText)
L = tk.Label(top,text='orignal text')
Many thanks to my correspondent for triggering this question / post - I've modified his code to show how to change the GUI behaviour. Readers may have noticed a reduction in technical answers such as this one of late - partly because there's so much going on, and partly because we already have a huge resource of answers and can point people to them when asked about things. Just occasionally, I'm still posting new descriptions of issues such as this one to keep them fresh, modern and perhaps to give better answers than I have in the past (written 2014-04-06)
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articlesY204 - Python - The TkInter GUI 
Tkinter - an easy to use Python Graphic User Interface - introductory examples - (2011-10-13)Q910 - Object Orientation and General technical topics - GUI principles 
Principles or a GUI and their practical application using wxPthon - (2015-11-30) 
wxPython - simple example to add GUI to a server log file analysis - (2010-12-08) 
Model - View - Controller demo, Sqlite - Python 3 - Qt4 - (2010-04-29)T224 - Tcl/Tk - Events in Tk 
Multiple buttons calling the same proc in wish (tcl/tk) - (2012-01-12) 
Making a variable dynamically visible in a Tcl/Tk GUI - (2007-12-15) 
What is a callback? - (2005-07-22)
Some other Articles
Updated staff systems helps us look after our customers betterUpdated delegate computers - nine of the bestWhy we teach LuaUpgrading our training systems to all the current stable versionsKeeping you Tkinter display up to date while monitoringOver a pound a kilometre - my bus in Weston-super-mareTrain fare look expensive? There may be a cheaper optionMaking a personal gain from a more expensive business hotel stayWhere is Melksham Market? In the Market Place, every TuesdayEaster Weeks - Melksham to Weymouth
4759 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, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page
This is a page archived from The Horse's Mouth at
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).