-Q2.E.5- scroll a canvas an a listbox at the same time with one scrollbar?

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

A2.E.5. From "David Herron" <david@twg.com>:

You need to write different code to handle the scrollcommand's.  Look at the
man page for `scrollbar' (and `listbox') and you see that it appends some
numbers to the scrollcommand such that your scrollbar command is executed as:

	.f.c yview; .f.lb yview <offset>

What I ended up doing is appended.  This code has an advantage in that
scrolling is constrained to "look right".

	listbox .l1	-relief sunken -yscrollcommand {
			scrollMultiple_y { .l1 .l2 .l3 } .vs
		}
	listbox .l2	-relief sunken -yscrollcommand {
			scrollMultiple_y { .l1 .l2 .l3 } .vs
		}
	listbox .l3	-relief sunken -yscrollcommand {
			scrollMultiple_y { .l1 .l2 .l3 } .vs
		}
	scrollbar .vs	-relief sunken -orient vertical \
			-command {setMultiple_y {.l1 .l2 .l3}}

	bind .l1 <1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l1 <B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l1 <Shift-1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l1 <Shift-B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}

	bind .l2 <1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l2 <B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l2 <Shift-1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l2 <Shift-B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}

	bind .l3 <1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l3 <B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l3 <Shift-1> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}
	bind .l3 <Shift-B1-Motion> {
		selectMultiple {.l1 .l2 .l3} [%W nearest %y]
	}

proc scrollMultiple_y {lists vs total window first last} {
	if {[expr $first+$window] > $total} {
		set first [expr $total-$window]
		set last  [expr $first+$window]
	}
	setMultiple_y $lists $first
	$vs set $total $window $first $last
}
proc setMultiple_y  {lists index} {
	foreach l $lists { $l yview $index }
}
proc selectMultiple {lists index} {
	foreach l $lists { $l select from $index }
}

Parent document is top of "FAQ: comp.lang.tcl Tk Toolkit Usage Questions And Answers (1/1)"
Previous document is "-Q2.E.4- detect when the canvas has been resized?"
Next document is "-Q2.E.6- use a list of coordinates in a variable to create a polygon (or any other item)?"