O'Reilly logo

Mastering Perl/Tk by Nancy Walsh, Stephen Lidie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Retrieving Elements

The get method returns a list of Listbox elements specified by the indexes firstindex tolastindex:

$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 curselection method is used:

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

Remember that curselection returns a list of indexes, not elements.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required