package require treectrl |
set T [treectrl .myTreeCtrl ?option value ...?] |
set columnID [$T column create ?option value ...?] |
Note There is a special column called the tail column that is created when the treectrl window is created. The tail column always appears to the right of any other columns created by the [$T column create] command. It is not possible to delete the tail column. |
set itemID [$T item create ?option value ...?] |
Note The root item is created when a treectrl window is created. It is not possible to delete the root item. |
$T
item firstchild
$parent $child $T item lastchild $parent $child $T item nextsibling $item $sibling $T item prevsibling $item $sibling |
Note An item can only be a child of a single parent. Also, you cannot make the root item a child of another item. |
$T item remove $item |
Note An item without a parent is known as an orphan and is never displayed in the treectrl window. You can get a list of orphan items using the command [$T orphans]. |
$T element
create
myElement1 image ?option
value...? $T element create myElement2 text ?option value...? |
$T style create myStyle1 ?option value...? |
Note There is no limit on the number of styles or elements that may be created in a treectrl window. |
$T style elements myStyle1 [list myElement1 myElement2] |
Note An element can be used only once by a particular style. However, the same element can be used by more than one style at a time. |
$T item style set $itemID $columnID myStyle1 |
$T item element configure $itemID $columnID myElement2 ?option value...? |
$T style layout myStyle1 myElement1 ?option value...? |
package require treectrl treectrl .t pack .t set column [.t column create -text hello -width 150 -itembackground linen] .t element create elemGray rect -fill gray -width 20 -height 10 .t element create elemBlue rect -fill blue -width 20 -height 30 .t element create elemGreen rect -fill green -width 20 -height 20 .t style create style1 .t style elements style1 {elemGray elemBlue elemGreen} .t item style set root $column style1 |
.t style layout style1 elemBlue -padx 4 -pady 2 |
.t style layout style1 elemGreen -expand n |
.t style layout style1 elemGreen -expand ns |
.t style layout style1 elemGray -iexpand y |
.t style layout style1 elemGray -iexpand xy |
.t style layout style1 elemGray -sticky "" |
.t style layout style1 elemGray -sticky w |
.t style layout style1 elemGray -sticky ws |
.t style layout style1 elemGray -sticky wnes |
Note Some elements like text and images are not stretched by the -sticky option. |
.t style layout style1 elemGray -detach yes |
.t style layout style1 elemGray -union elemGreen |
.t style layout style1 elemGray -ipadx 4 -ipady 4 |
.t style layout style1 elemGray -iexpand n |
.t style layout style1 elemGray -iexpand ns |
package require treectrl treectrl .t -showheader no -showroot no -width 250 pack .t set columnID [.t column create] .t element create elemBorder border -background #ece9d8 -filled yes -relief solid -thickness 1 .t element create elemText text .t style create style1 .t style elements style1 {elemBorder elemText} .t style layout style1 elemBorder -union elemText -ipadx 4 -ipady 4 .t style layout style1 elemText for {set i 1} {$i <= 20} {incr i} { set itemID [.t item create] .t item style set $itemID $columnID style1 .t item element configure $itemID $columnID elemText -text "Item $i" .t item lastchild root $itemID } |
.t configure -orient horizontal |
.t configure -wrap "5 items" |
.t configure -wrap window |
.t configure -width 200 |
.t configure -width 250 -wrap "200 pixels" |
.t configure -orient vertical -wrap window |
package require treectrl treectrl .t -showheader no -showroot no -width 410 -height 300 pack .t -expand yes -fill both set columnID [.t column create -itembackground linen] .t element create elemBorder border -background #ece9d8 -filled yes -relief solid -thickness 1 .t element create elemText text .t style create style1 .t style elements style1 {elemBorder elemText} .t style layout style1 elemBorder -union {elemText} -ipadx 4 -ipady 4 .t style layout style1 elemText foreach n {5 15 20 10 10 5 15 10 20 15 15 25 10 5 15 5 10 20 15 25} { set itemID [.t item create] .t item style set $itemID $columnID style1 set text [string range "abcdefghijklmnopqrstuvwxyz" 0 $n] .t item element configure $itemID $columnID elemText -text $text .t item lastchild root $itemID } |
.t column configure $columnID -width 200 |
.t configure -wrap "10 items" |
.t column configure $columnID -width "" |
.t configure -itemwidthequal yes |
.t configure -itemwidthequal no -orient horizontal -wrap window |
.t configure -itemwidthmultiple 100 |
.t configure -itemwidthmultiple "" -itemwidth 100 |
Situation (-orient vertical) | How an item's width is determined | Items have equal width? |
---|---|---|
More than one column is visible | sum of the calculated widths of all visible columns | yes |
-wrap == "" | column's calculated width | yes |
-itemwidth > 0 | -itemwidth option | yes |
column -width != "" | column's -width option Using the column's -width option this way is deprecated. Use the treectrl's -itemwidth option instead. |
yes |
-itemwidthequal == true | width of widest item round up using -itemwidthmultiple |
yes |
all other cases | requested width of style, plus indentation if this is the tree column round up using -itemwidthmultiple |
All items in a range have the same width, but each range may have a different width. |
Situation (-orient horizontal) | How an item's width is determined | Items have equal width? |
---|---|---|
More than one column is visible | sum of the calculated widths of all visible columns | yes |
-itemwidth > 0 | -itemwidth option | yes |
column -width != "" | column's -width option Using the column's -width option this way is deprecated. Use the treectrl's -itemwidth option instead. |
yes |
-itemwidthequal == true | width of widest item round up using -itemwidthmultiple |
yes |
all other cases | requested width of style, plus indentation if this is the tree column round up using -itemwidthmultiple |
no |
package require treectrl treectrl .t -width 400 -height 300 -showrootbutton yes pack .t -expand yes -fill both set columnID [.t column create -text "Column 0"] .t configure -treecolumn $columnID .t element create elemBorder border -background #ece9d8 -filled yes -relief solid -thickness 1 .t element create elemText text .t style create style1 .t style elements style1 {elemBorder elemText} .t style layout style1 elemBorder -union {elemText} -ipadx 4 -ipady 4 .t style layout style1 elemText .t item configure root -button yes .t item style set root $columnID style1 .t item element configure root $columnID elemText -text "The root item" for {set i 1} {$i <= 100} {incr i} { set itemID [.t item create -button yes] .t item collapse $itemID .t item style set $itemID $columnID style1 .t item element configure $itemID $columnID elemText -text "Item $itemID" .t item lastchild root $itemID } |
.t notify bind .t <Expand-before> { AddChildItems %T %I } proc AddChildItems {tree parent} { if {[$tree item numchildren $parent] > 0} return set columnID first for {set i 1} {$i <= 100} {incr i} { set itemID [$tree item create -button yes] $tree item collapse $itemID $tree item style set $itemID $columnID style1 $tree item element configure $itemID $columnID elemText -text "Item $itemID" $tree item lastchild $parent $itemID } return } |