Skip to Main Content
Learning Perl/Tk
book

Learning Perl/Tk

by Nancy Walsh
January 1999
Beginner content levelBeginner
373 pages
9h 43m
English
O'Reilly Media, Inc.
Content preview from Learning Perl/Tk

7.10. Selection Methods

The curselectionmethod, discussed in the preceding section, only tells you what the user has selected. You can also change the selection by using a form of the selection method.

7.10.1. Selecting Items

To select a range of items in a listbox, you can use the "set" form of the selection method (selectionSet). selectionSet takes either a single index or a range. Any items not in the range are not affected. If you use a range, the first index must be less than or equal to the last index. Here are some examples:

# select everything
$lb->selectionSet(0, 'end' );
#select the first item
$lb->selectionSet(0);

Even if you have used -selectmode to limit the selection to only one item, you can force more than one item to be selected by using selectionSet(...).

7.10.2. Unselecting Items

To clear any selections in the listbox, use the "clear" form of the selection method (selectionClear). Pass in an index or a range or indexes from which to clear the selection. For instance, to remove all the selections in the listbox, you would do the following:

$lb->selectionClear(0, "end");

Any indexes outside the specified range will not be unselected—this allows you to unselect one item at a time. You can also clear the selection from just one item:

$lb->selectionClear("end");

7.10.3. Testing for Selection

To test to see if a specific index is already selected, use the "includes" form of selection (selectionIncludes). Calling selectionIncludes returns 1 if the item at the specified ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering Perl/Tk

Mastering Perl/Tk

Stephen Lidie, Nancy Walsh

Publisher Resources

ISBN: 1565923146Supplemental ContentCatalog PageErrata