modcopy - tips & tricks (original) (raw)

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

Tix Grid with full implementation of all methods

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