TreeWidget

1 Function

TreeWidget is a Python MegaWidget which displays a tree structure in a Tkinter text widget. Each tree node is displayed in one line, indented according to its depth. This gives a presentation similar to a hierarchical content table. The presentation of internal nodes can be folded (collapsed) or expanded. Folding removes the node's descendants from the display, expansion adds children or (optionally) descendants further down the line. Icons before the node representation show whether the node can be collapsed, expanded or is a leave.

The widget provides an update method to synchronize the display with a dynamically modified tree. It tries to keep a node's display state (expanded/collapsed) unchanged during updates (but may collapse expanded nodes for some forms of changes, e.g. reordering of children).

The widget tries hard to release internal resources early, allowing it to display dynamic trees associated with scarce resources.

TreeWidget uses Greg McFarlane's excellent Python MegaWidget Framework.

2 Usage Conditions

TreeWidget can be used under a Python like license. See the copyright notice at the start of TreeWidget.py, for details.

3 Alternatives

I know of three alternatives:
  1. the TreeExplorer in Doug Hellmann's PmwContribD package
    It is easier to use than my TreeWidget and provides nicer symbols. It seems, however, not to support dynamically changing trees and early resource release.
  2. the TreeWidget class in Guido's IDLE package
    In my TreeWidget module some things on Guido's todo list are done, especially partial and total redisplay (to support changing trees), keeping track of object ids, early release of functions implicitely defined for bindings. My TreeWidget is implemented as Pmw MegaWidget and uses a Pmw.ScrolledText as medium for tree display; Guido only requires plain Tkinter and uses a Canvas for tree display. His icon management is fancier. He supports more features in the basic infrastructure (double clicking opens/closes node, items are editable) that must be provided by the application in my framework (if they are needed).
  3. Gene Cash's tree.py
    I did not yet look at it closely. The announcement, however, seems promissing: canvas based, speed independent of tree size, tries to narrowly emulate the Windows tree control (used e.g. by Windows explorer). Only nasty thing: GPL license (Martin Armstrong reported on 2002-08-12, that this is no longer true).
Probably, there are more alternative, I do not (yet) know about.

4 Requirements

TreeWidget requires Pmw and of cause Python to be installed. It has been tested with Pmw 0.8.0/0.8.1/0.8.3 and Python 1.5.2 but may run with other versions, too.

5 Download

TreeWidget version 0.05 can be downloaded as an 8 kB tgz archive.

6 Example

The package contains a trivial file system viewer fstree.py. Start it by python fstree.py folder_to_view. Beside the usual folding/unfolding, <Button-1> applied to the label of an item updates the corresponding subtree.

7 Versions

7.1 Version 0.05

7.2 Version 0.04

7.3 Version 0.03

7.4 Version 0.02


Dieter Maurer
Last modified: Wed Aug 14 18:47:12 CEST 2002