Posted to tcl by bleb at Tue Nov 07 18:45:11 GMT 2023view raw

  1. #!/usr/bin/wish
  2.  
  3. proc Scrolled_Text { f args } {
  4. frame $f
  5. eval {text $f.text -wrap none \
  6. -xscrollcommand [list $f.xscroll set] \
  7. -yscrollcommand [list $f.yscroll set]} $args
  8. scrollbar $f.xscroll -orient horizontal \
  9. -command [list $f.text xview]
  10. scrollbar $f.yscroll -orient vertical \
  11. -command [list $f.text yview]
  12. grid $f.text $f.yscroll -sticky news
  13. grid $f.xscroll -sticky news
  14. grid rowconfigure $f 0 -weight 1
  15. grid columnconfigure $f 0 -weight 1
  16. return $f.text
  17. }
  18. set t [Scrolled_Text .f -width 40 -height 8]
  19. pack .f -side top -fill both -expand true
  20.  
  21. set l [list a b c]
  22.  
  23. foreach i {0 1 2} {
  24. puts "i: [lindex $l $i]"
  25. $t tag bind link[lindex $l $i] <1> {$t insert end "CLICK: [lindex $l $i]\n"}
  26. $t insert end "-> $i <-\n" link[lindex $l $i]
  27. }