A Pair of Listboxes Working Together

The two listboxes in the interface, $frame.key and $frame.cmd, are set up to work as a unit. A selection in one causes a parallel selection in the other. Only one listbox exports its selection as the PRIMARY selection. Otherwise, the last listbox to assert the selection steals the selection rights from the other widget. The following example shows the bind commands from Bind_Interface and the BindSelect routine that selects an item in both listboxes:

Example 43-3 Related listboxes are configured to select items together.
foreach l [list $frame.key $frame.cmd] {
   bind $l <Button-1> \
      [list BindSelect %y $frame.key $frame.cmd]
   bind $l <B1-Motion> \
      [list BindSelect %y $frame.key $frame.cmd]
}
proc BindSelect ...

Get Practical Programming in Tcl & Tk, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.