http://www.tcl.tk/man/tcl8.5/TkCmd/ttk_treeview.htm
This is the treeview widget of the Tile widget set. The treeview widget is intended to provide something that's a little more powerful (and faster) than the BWidget::Tree widget, and a little bit simpler to use (though less powerful) than the TkTreeCtrl widget.
The screenshot below shows the treeview as part of a larger program (using the clam theme). There is a header and 6 entries (where two are one level down).
The basics of this widget are:
package require tile tile::setTheme clam # create it: ttk::treeview .tree pack .tree -expand 1 -fill both # insert an entry at the root level: set entry1 [.tree insert {} end -text "first item"] # and a second one: set entry2 [.tree insert {} end -text "second item"] # insert a new level with entry1 as parent: .tree insert $entry1 end -text "a sublevel" # insert another item under this one: .tree insert $entry1 end -text "another item" # suppose, one item is selected. # we can then delete it thus: .tree delete [.tree selection]
# Also, to add the heading: .tree heading #0 -text Features # I also like the heading a little closer to the frame .tree configure -padding {0 0 0 0}
SLB For an example of how to implement sorting in treeview see Tile Table
Sarnold uses a BWidget Tree in which some data is associated with each entry. ttk::treeview does not seem - to my great surprise - to handle other data than the text. Is it true ? Is adding such a feature planned ?
JH I found the old-school border style of treeview on xpnative to be unsatisfactory. Pat pointed out this helpful alternative layout:
ttk::style layout Treeview { Entry.field -sticky news -border 2 -children { Treeview.padding -sticky news -children { Treeview.treearea -sticky news } } }
You can remove the Entry.field outer part to have purely no border as well. This is good when wrapping it in something like widget::scrolledwindow.
MAKR 2009-05-22: Inplace edit in ttk::treeview is another example, how to use this widget.
RLH Is the "arrow" the only option for the toggle?