7.3. Selection Modes
As part of the Listbox widget,
several choices exist for the way you can select items in the
Listbox. You can have it so only one item at a time can be selected
(emulating Radiobuttons) or you can have many different contiguous or
noncontiguous items selected (emulating Checkbuttons). You control
this behavior with the -selectmode option.
select modes are "browse",
"single", "multiple", or
"extended". The default mode is
- browse and single
These modes are similar in that only one
item can be selected at a time; clicking on any item will deselect
any other selection in the Listbox. The browse
mode has a slight difference: when the mouse is held down and moving
around, the selection moves with the mouse. For
bind purposes, a
"<Button-1>" bind will be invoked when you
first click down. If you want to catch the event when the mouse is
released, define a ButtonRelease binding. (Binding
events to widgets is discussed in Chapter 15, "Anatomy of the MainLoop".)
This mode lets you select more than one item at a time. Clicking on a
single item with the left mouse button will deselect any other
selection, but you can Shift-click or Control-click to add more items
to your selection. Shift-clicking (holding down the Shift key while
pressing a mouse button) will extend the selection from the already
selected item to the newly selected item. Control-clicking (holding
down the Control key while pressing a mouse button) will add the item
being clicked to the selection, but it won't alter any of the
other selections. You can also click an item with the mouse button,
hold down the button, and then move the pointer over other items to
select them. This is what's called a click-drag motion. Using
"extended" allows for very fast selection of many
different items in the Listbox.
This mode also allows you to select more than one item. Instead of
Shift-clicking or Control-clicking, you select items one at a time.
Clicking on an unselected item will select it, and clicking on an
already selected item will unselect it.
7.3.1. Operating System Differences
-selectmode feature on Windows 95 does not allow
the "multiple" selection mode, it behaves the same
as "single" mode. On Unix and Windows NT,
"multiple" mode works correctly.
When you select an item in a Listbox, by
default it is made available as an X selection (meaning you can cut
and paste it like any X selection in any window). Though this
doesn't do anything with the clipboard on Win32 systems, it
still affects the selection in multiple Listboxes. Items can be
selected in only one Listbox at a time, even if you have more than
one Listbox. The option -exportselection controls this. Use -exportselection =>
0 to allow items to be selected in more than one Listbox at
the same time.
Copyright © 2002 O'Reilly & Associates. All rights reserved.