Posted to tcl by bleb at Tue Nov 07 18:12:14 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. foreach i { 1 2 3 } {
  22. puts "i: $i"
  23. $t tag bind link$i <1> {$t insert end "CLICK: $i\n"}
  24. $t insert end "-> $i <-\n" link$i
  25. }
  26.