Posted to tcl by jdc at Fri Jun 20 07:30:58 GMT 2008view raw

  1. package require Tk
  2.  
  3. set ltxt [text .ltxt]
  4. set rtxt [text .rtxt -xscrollcommand [list .sx set]]
  5. set sx [scrollbar .sx -orient horizontal -command [list $rtxt xview]]
  6. set sy [scrollbar .sy -orient vertical]
  7.  
  8. proc yset { t1 t2 sy args } {
  9. $t1 yview moveto [lindex $args 0]
  10. $t2 yview moveto [lindex $args 0]
  11. eval $sy set $args
  12. }
  13.  
  14. proc yview { t1 t2 sy args } {
  15. eval $t1 yview $args
  16. eval $t2 yview $args
  17. }
  18.  
  19. $ltxt configure -yscrollcommand [list yset $ltxt $rtxt $sy]
  20. $rtxt configure -yscrollcommand [list yset $ltxt $rtxt $sy]
  21. $sy configure -command [list yview $ltxt $rtxt $sy]
  22.  
  23. grid $ltxt $rtxt $sy -sticky ewns
  24. grid $sx - -sticky ewns
  25. grid columnconfigure . 0 -weight 1
  26. grid rowconfigure . 0 -weight 1
  27.  
  28. for {set i 0 } { $i < 100 } { incr i } {
  29. $ltxt insert end "left $i\n"
  30. $rtxt insert end "right $i\n"
  31. }