tips & tricks

I have recently started development for a small video conversion project using a GUI. After some research I decided to use Tkinter/Tix (Tk/Tix). The reasons are mainly:
  1. the GUI is rather simple, and
  2. the end-user is not necessarily technically inclined so I want to keep
    a) required libraries as few as possible, and
    b) installation as painless as possible.
  3. Tk/Tix is included with Python. Thus only a Python installation is needed. Nothing else.
  4. Tk itsself misses some rudimentary widgets like meters, multi/colum lists, grid and scrolled widgets. Tix provides those. Good enough for my little application (more advanced and more modern widgets are available in frameworks like Qt, Gtk, or wxWindows).
Before starting I spent some effort to find
  1. relevant documentation,
  2. GUI Builders which might help me,
  3. answers to non-obvious questions.
The process took some time and effort so I want to share my findings:

documentation

Python Docs
http://docs.python.org/library/tkinter.html

Tk Commands

http://www.tcl.tk/man/tcl8.5/TkCmd/contents.htm

Tix Reference

http://tix.sourceforge.net/man/html/contents.htm

Tix demo application

You want to extract the Tix demo application coming with the Tix 8.4.3 source distribution. It contains examples for many widgets - unfortunately none for multi-column HList or the Grid (see below).
https://sourceforge.net/project/showfiles.php?group_id=5649&package_id=5704
Tix8.4.3-src.tar.gz, then look in /Tix8.4.3/Python/Demo/tix

Thinking in Tkinter - 1

I recommend the "Individual programs online"
http://www.ferg.org/thinking_in_tkinter/index.html

Thinking in Tkinter - 2
This is a different thing from the above full of nice examples.
http://effbot.org/tkinterbook/
How to add scrollbars to widgets. Very much recommended!
http://effbot.org/zone/tkinter-scrollbar-patterns.htm#the-scrollbar-interface
Tkinter reference: a GUI for Python
http://infohost.nmt.edu/tcc/help/pubs/tkinter.pdf


GUI Builders

ActiveState GUI Builder (using grid layout)
SpecTcl is the predecessor of GUI Builder (by ActivaState).
http://spectcl.sourceforge.net/

FAQ (where to get source)
http://aspn.activestate.com/ASPN/Mail/Message/komodo-announce/3355346

PAGE v3.0 by Stewart Allen (using placer layout)
http://page.sourceforge.net/

There are many more for other GUI toolkits mentioned in this post:
http://mail.python.org/pipermail/python-list/2004-February/250727.html


Finally I decided to use the packer layout and create the widgets manually. Just the simplest and quickest way for me.

FAQ

How do I use all methods available in the Tix Grid?

Tix Grid with full implementation of all methods

http://klappnase.bubble.org/TixGrid/index.html


How do I create a multi-column Tix.HList?

import Tkinter as Tk
import Tix

root = Tix.Tk()
# setup HList
hl = Tix.HList(root, columns = 5, header = True)
hl.header_create(0, text = "File")
hl.header_create(1, text = "Date")
hl.header_create(1, text = "Size")
# create a multi-column row
hl.add("row1", text = "filename.txt")
hl.item_create(entry_path, 1, text = "2009-03-26 21:07:03")
hl.item_create(entry_path, 2, text = "200MiB")

How do I modify the style of a column?

style['header'] = Tix.DisplayStyle(Tix.TEXT, refwindow=hlist,       anchor=Tix.CENTER, padx=8, pady=2, font = boldfont )
hlist.header_create(0, itemtype=Tix.TEXT, text='Name', style=style['header'])

This is an excerpt from the example program SHList2.py in Tix8.4.3\Python\Demo\tix\samples.

How to implement Tk GUI with multiple threads?

Usually there are two options to make threads wait for an event:

Best practice

For multithreading Python Tk GUI applications the following rules apply:
  1. same thread calling Tk must do all subsequent GUI calls,
  2. other threads may send events with send_event to the root Tk instance,
  3. with threading problems you might try to synchronise access to event_generate(). Using event_generate() with only one non-GUI thread has found not to be safe