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.)


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, ...

Get Mastering Perl/Tk now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.