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.9. Retrieving Elements

The get method returns a list of listbox elements specified by the indexes first to last:

$lb->get(firstindex
				[,  lastindex ]);

If only the firstindex is specified, only one element is returned. The firstindex must be less than or equal to the lastindex. To get a list of all elements in the listbox:

@elements = $lb->get(0, 'end');

To get the last item in the listbox:

$lastitem = $lb=>get('end');

To find out which items in the listbox are selected, use the curselectionmethod:

@list = $lb->curselection();

It returns a list containing the indexes of all currently selected items in the listbox. If no items are selected, curselection returns an empty string. Here is an example of how the curselectionmethod is used:

@selected = $lb->curselection;
foreach (@selected) {
  # do something with the index in $_
}

Make sure to remember that curselection returns a list of indexes, not elements.

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