Training, Open Source Programming Languages

This is page http://www.wellho.net/mouth/4258_Kee ... oring.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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
T224 - Tcl/Tk - Events in Tk
  [386] What is a callback? - (2005-07-22)
  [1473] Making a variable dynamically visible in a Tcl/Tk GUI - (2007-12-15)
  [3575] Multiple buttons calling the same proc in wish (tcl/tk) - (2012-01-12)

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

Y204 - Python - The TkInter GUI
  [3476] Tkinter - an easy to use Python Graphic User Interface - introductory examples - (2011-10-13)


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
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 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).

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
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: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb