Posted to tcl by nscerqueira at Mon May 27 21:55:59 GMT 2013view raw

  1. : # Demo code
  2. #
  3.  
  4.  
  5. ::ttk::treeview .tree -height 15 -show tree \
  6. -yscroll ".vsb set" -xscroll ".hsb set" -selectmode browse
  7. ::ttk::scrollbar .vsb -orient vertical -command ".tree yview"
  8. ::ttk::scrollbar .hsb -orient horizontal -command ".tree xview"
  9.  
  10. grid .tree .vsb -sticky nsew
  11. grid .hsb -sticky nsew
  12. grid column . 0 -weight 1
  13. grid row . 1 -weight 1
  14.  
  15. ## Create Data Set
  16. foreach txt {first second third} {
  17. set id [.tree insert {} end -text "$txt item" -open 1]
  18.  
  19. for {set i [expr {1+int(rand()*5)}]} {$i > 0} {incr i -1} {
  20. set child [.tree insert $id 0 -text "child $i"]
  21.  
  22. for {set j [expr {int(rand()*3)}]} {$j > 0} {incr j -1} {
  23. .tree insert $child 0 -text "grandchild $i"
  24. }
  25. }
  26. }