Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python, Lua, Tcl, C and C++ training - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, Ruby, MySQL and Linux / Tomcat systems
 
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.

  #!/usr/bin/env python
   
  import Tkinter as tk
  import time
   
  top = tk.Tk()
   
  def addText():
    # make first change
    oldText = L.cget("text")
    newText = oldText + '\nfirst change'
    L.configure(text=newText)
   
    # wait 2 seconds
    top.update_idletasks()
    time.sleep(2)
   
    # make second change
    newText += '\nsecond change'
    L.configure(text=newText)
   
  B = tk.Button(top, text ="Change text", command = addText)
  L = tk.Label(top,text='orignal text')
   
  B.pack()
  L.pack()
  top.mainloop()


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 articles
Y204 - Python - The TkInter GUI
  [3476] Tkinter - an easy to use Python Graphic User Interface - introductory examples - (2011-10-13)

Q910 - Object Orientation and General technical topics - GUI principles
  [4589] Principles or a GUI and their practical application using wxPthon - (2015-11-30)
  [3081] wxPython - simple example to add GUI to a server log file analysis - (2010-12-08)
  [2746] Model - View - Controller demo, Sqlite - Python 3 - Qt4 - (2010-04-29)

T224 - Tcl/Tk - Events in Tk
  [3575] Multiple buttons calling the same proc in wish (tcl/tk) - (2012-01-12)
  [1473] Making a variable dynamically visible in a Tcl/Tk GUI - (2007-12-15)
  [386] What is a callback? - (2005-07-22)


Back to
Over a pound a kilometre - my bus in Weston-super-mare
Previous and next
or
Horse's mouth home
Forward to
Upgrading our training systems to all the current stable versions
Some other Articles
Updated staff systems helps us look after our customers better
Updated delegate computers - nine of the best
Why we teach Lua
Upgrading our training systems to all the current stable versions
Keeping you Tkinter display up to date while monitoring
Over a pound a kilometre - my bus in Weston-super-mare
Train fare look expensive? There may be a cheaper option
Making a personal gain from a more expensive business hotel stay
Where is Melksham Market? In the Market Place, every Tuesday
Easter Weeks - Melksham to Weymouth
4754 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 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).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2017: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4258_Kee ... oring.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat