Version 2 of multi scrolling

Updated 2003-07-02 22:16:29

ulis, 2003-07-02: How to scroll two widgets at the same time. Or: synchronized listboxes.


  # ---------------
  # multi scrolling
  # ---------------

  # creating the widgets
  frame .f
  foreach n {0 1 2 3 4 5 6 7 8 9} { lappend list1 item1-$n }
  foreach n {0 1 2 3 4 5 6 7 8 9} { lappend list2 item2-$n }
  listbox .f.lb1 -list ::list1 -height 8 -yscrollc yset
  listbox .f.lb2 -list ::list2 -height 8 -yscrollc yset
  scrollbar .f.sb -command yview
  # placing & showing the widgets
  pack .f
  grid .f.lb1 -row 0 -column 0
  grid .f.lb2 -row 0 -column 1
  grid .f.sb -row 0 -column 2 -sticky ns
  # the scroll procs
    # called by a listbox
  proc yset {args} \
  {
    eval [linsert $args 0 .f.sb set]
    yview moveto [lindex [.f.sb get] 0]
  }
    # called by the scroll bar
  proc yview {args} \
  {
    eval [linsert $args 0 .f.lb1 yview]
    eval [linsert $args 0 .f.lb2 yview]
  }

Category Example | Category GUI | Category Widget