home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeMastering Perl/TkSearch this book

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.

The possible select modes are "browse", "single", "multiple", or "extended". The default mode is "browse".

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.

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.