G U I

5/17/21  Recently I posted what might be the last version of the tkinter toolbox which has, over the last six years,  been vetted, damned and praised by a gazillion Pythonistas from literally about 40 countries. (The new 16 page version has gotten 99% praise.)   Obviously I am a tkinter kind of guy, but I now have to add a big cognizance:  it is not what I would recommend learning to  beginning GUI programmers or Pythonistas who just need to create an occasional interface. That honor now goes soundly to a tkinter “wrapper” called PySimpleGUI. PSG will let you do in a few lines of code stuff that would take hours to create in tkinter unless you use tkinter daily. It is still something you have to learn  – its just a (much) better mousetrap.

GUI in Python with tkinter is not 1/2 as hard as some seem to think it is.  Part of the problem is the way the primary graphics modules have “grown up”.  This is one of those rare times when knowing a little history can actually help you be a better programmer. First there was “Tkinter” (note the capital letter “T” – very very important that you get this, it could save you days of frustration). Tkinter was originally part of a scripting language called TCL and Tkinter stands for Tk Interface.

But forget about Tkinter. It is dead and gone – or should be.  For Python 3.x and up an exciting, improved, easier to use and more stable GUI version was introduced.  And in a stroke of brilliance it was named – drum roll – hold on tight – wait for it – “tkinter”. Wait. Say what? Yep, some genius (which is probably literally true) decided to call it the same thing except use a small “t”.  He obviously did not know that Google is case insensitive – which means he royally screwed everybody trying to use it.

Fortunately a great deal of the syntax true for Tkinter is still appropriate for tkinter.  And speaking of that, we all owe a debt of thanks to a guy named John Shipman at New Mexico Tech for creating the most lucid, concise outline of Tkinter available.  5/11/2020 A url to John Shipman’s work used to be here but a kind reader let me know that his work is no longer online.  John passed away a couple of years ago and I guess New Mexico Tech did not understand the importance of his work or felt it has become dated.

John also included, almost as an afterthought, section “28. ttk: Themed widgets”.  “Themed widgets” is how I guess they first tried to sell some improvements and additions to tkinter. I have several things to say about ttk which, if imported, replaces a big chunk of tkinter. Once upon a time I posted a giant chart full of errors, duplicate date and omissions  called “Python tkinter, ttk, and tix toolbox”  – it is gone now but you can get the gist in the graphic below. It might help you understand how ttk was overlaid on tkinter.  “Plopped down on top of” might be a better description.

In doing so, ttk replaced many of the existing tkinter widgets, added some, and left some undisturbed. It did this so that it could eliminate more than half of the options  for which a programmer must/can make choices (or accept defaults) in favor of having all the widgets adhere to a “style” which are then collected into a “theme”. Some of the themes are:

  • winnative
  • clam
  • alt
  • default
  • classic
  • vista
  • xpnative

The widgets replaced are:

  • Button
  • Checkbutton
  • Entry
  • Radiobutton
  • Menubutton
  • Scale
  • Lable
  • Labelframe
  • Frame
  • PannedWindow
  • Scrollbar

The widgets added are:

  • ComboBox
  • Notebook
  • Progressbar
  • Sizegrip
  • Separator
  • Treeview

The tkinter widgets left in place are:

  • Text
  • Spinbox
  • Listbox
  • Message
  • Toplevel
  • Canvas
  • MessageBox

In my experience ttk is neither as user friendly or as stable as the tkinter widgets it replaces and it definitely complicates the programming process.

Note: TIX is unsupported and Python.org says do not use in future development.