# -Q2.D.5- scroll two listboxes with one scrollbar?

    From: -II-  Tk Questions and Answers - How can I:

    A2.D.5. Scrollbars have a '-command' option which is used to tell
    scrollable widgets (e.g. listbox, text, entry) how to position
    themselves when the scrollbar is moved.  This command typically
    looks like:
        scrollbar .scroll -command {.scrollable_widget yview}
    or
        scrollbar .scroll -command {.scrollable_widget xview}

    Before the command is executed, however, it will have a space and
    a number appended to it.  The number is a logical position index
    which indicates how the scrollable widget should position itself.
    Thus, to have a single scrollbar control two (or more) widgets,
    simply use a procedure as the scroll command, and have that
    procedure scroll as many widgets as you would like.  The procedure
    should take a single argument (i.e. the logical position index).
    For example:

        proc ScrollCommand {index} {
            .lb1 yview $index
            .lb2 yview $index
            .lb3 yview $index
        }

        scrollbar .scroll -command ScrollCommand

        listbox .lb1 -geometry 4x5 -yscrollcommand {.scroll set}
        listbox .lb2 -geometry 4x5 -yscrollcommand {.scroll set}
        listbox .lb3 -geometry 4x5 -yscrollcommand {.scroll set}
        pack .scroll .lb1 .lb2 .lb3 -side left -fill y

        .lb1 insert 0 a b c d e f g h i j
        .lb2 insert 0 0 1 2 3 4 5 6 7 8 9
        .lb3 insert 0 A B C D E F G H I J

Parent document is top of "FAQ: comp.lang.tcl Tk Toolkit Usage Questions And Answers (1/1)"
Previous document is "-Q2.D.4- avoid fractional white space at the end of a resizable listbox?"
Next document is "-Q2.D.6- have a listbox only allow the selection of a single item"