How to implement tk scrollbar for multiple listboxes (TCL)?

I tried all sort of options but no success in implement simple scrollbar for two or more listboxes. Following is my code giving error while scrolling. I hope you guys are helping me...

scrollbar .scroll -orient v
pack .scroll -side left -fill y
listbox .lis1
pack .lis1 -side left 
listbox .lis2
pack .lis2 -side left 

for {set x 0} {$x < 100} {incr x} {
 .lis1 insert end $x
 .lis2 insert end $x
.lis1 configure -yscrollcommand [list .scroll set]
.lis2 configure -yscrollcommand [list .scroll set]
.scroll configure -command ".lis1 yview .lis2 yview ";

thanking you.

There are a number of examples on the Tcler's wiki, but the core principle is to use a procedure to ensure that the scrolling protocol is synchronized between the widgets. Here's an example based off that wiki page:

# Some data to scroll through
set ::items [lrepeat 10 {*}"The quick brown fox jumps over the lazy dog."]

# Some widgets that will scroll together
listbox .list1 -listvar ::items -yscrollcommand {setScroll .scroll}
listbox .list2 -listvar ::items -yscrollcommand {setScroll .scroll}
scrollbar .scroll -orient vertical -command {synchScroll {.list1 .list2} yview}

# The connectors
proc setScroll {s args} {
    $s set {*}$args
    {*}[$s cget -command] moveto [lindex [$s get] 0]
proc synchScroll {widgets args} {
    foreach w $widgets {$w {*}$args}

# Put the GUI together
pack .list1 .scroll .list2 -side left -fill y 

It's worth noting that you can also plug any other scrollable widget into this scheme; everything in Tk scrolls the same way (except with -xscrollcommand and xview for horizontal scrolling, together with a change of scrollbar orientation). Furthermore, the connectors here, unlike the ones on the wiki page, can be used with multiple groups of scrolled widgets at once; the knowledge of what is scrolled together is stored in the -command option of the scrollbar (first argument to synchScroll callback).

[EDIT]: For 8.4 and before, you need slightly different connector procedures:

# The connectors
proc setScroll {s args} {
    eval [list $s set] $args
    eval [$s cget -command] [list moveto [lindex [$s get] 0]]
proc synchScroll {widgets args} {
    foreach w $widgets {eval [list $w] $args}

Everything else will be the same.

windows, There are a number of examples on the Tcler's wiki, but the core principle is to use a procedure to ensure that the scrolling protocol is  Set the scrollbar’s command to the yview method of the widget. When the widget view is modified, the widget notifies the scrollbar by calling the set method. And when the user manipulates the scrollbar, the widget’s yview method is called with the appropriate arguments. Adding a horizontal scrollbar is as simple.

If you plan to do much work in the the callback command - make a procedure to do it as that is both faster (the procedure gets byte compiled) and less likely to introduce tcl syntax problems. In this case you are trying to perform two tcl commands in the scrollbar function so you need to separate the statements using newline or a semicolon.

Calling the scrollbar set function from both listboxes will just have the second one override the first. You either need a function to merge those two or if the lists have the same lengths, just call it from one of them to set the scrollbar size and position and then update all listboxes with the scrollbar callback.

There is a multilistbox package somewhere - try the Tcl wiki to locate examples.

How can I scroll multiple listboxes with one scrollbar?, 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  It may have any of the forms accepted by Tk_GetColor. pathName nearest y Given a y-coordinate within the listbox window, this command returns the index of the (visible) listbox element nearest to that y-coordinate. pathName scan option args This command is used to implement scanning on listboxes. It has two forms, depending on option:

I know that this post is really old but I recently discovered what I think is a fairly simple solution. Instead of using the vertical scrollbar I found that I can use the slider widget. With the slider you can get the position of the slider and use that to set the yview of the listbox(es). Multiple listboxes can be scrolled simultaneously. I use vtcl to build the GUI so the code I can provide may not beimmediately obvious for those using tk wm comands. But here is the code I use. It is bound to slider motion.

set listIndex [$widget(Scale1) get]
$widget(Listbox1) yview $listIndex
$widget(Listbox2) yview $listIndex

Hope that is helpful to somebody.

Tcl/Tk: A Developer's Guide, Example 39 # scrollbar The name of the scrollbar # listbox1 The. Script. Example. # Create two listboxes listbox .leftbox −height 5 −exportselection 0 listbox  Tk automatically creates class bindings for listboxes that give them Motif-like behavior. Much of the behavior of a listbox is determined by its selectMode option, which selects one of four ways of dealing with the selection. If the selection mode is single or browse, at most one element can be selected in the listbox at once. In both modes

Tcl and the Tk Toolkit, The script implementing the listbox in Figure 18.12 manipulates the associated and a listbox working together Figure 18.14 Scrolling multiple widgets together. Labels. wish label.tcl. Labels are widgets that contain text or images. You can specifiy the text, its font, how its justified, color, etc. #Create three different labels label .l1 -text "This is what the default label looks like" label .l2 -text "This is a yellow label on a blue background" \ -foreground Yellow \ -background Blue label .l3 -text "This is a label in Times 24 font" \ -font

Text widget/listbox synchronous multi-scrolling? (Tcl/Tk), I saw this solution here: How to implement tk scrollbar for multiple listboxes (​TCL)? The problem is it's not working for me exactly. When I click on the scrollbar​  This is a compound widget that gangs multiple Tk Listboxes to a single scrollbar to achieve a simple multi-column scrolled listbox. Most of the Listbox API is mirrored to make it act like the normal Listbox but with multiple values per row.

Tk 4+ Usage FAQ (Frequently Asked Questions), For additional information on Tcl as well as pointers to other documentation and code, see the FAQ maintained by Larry How can I get Tk to use send (I get security error messages)? How can I scroll multiple listboxes with one scrollbar​? A procedure to be called whenever the scrollbar is moved. 5: cursor. The cursor that appears when the mouse is over the scrollbar. 6: elementborderwidth. The width of the borders around the arrowheads and slider. The default is elementborderwidth=-1, which means to use the value of the borderwidth option. 7: highlightbackground

  • Thanks...I think this works in tcltk 8.5 And I am working on 8.4(still) so not working for me. But I try to use your base to start.
  • thanks "patthoyts"... I wanted too understand this in detail, instead of just completing it.