Listbox Methods

In addition to configure and cget, the following methods are supported by Listbox:

insert

Adds items to a listbox at the specified index. For example, to insert items at the end of a list:

$listbox->insert('end', "Puerto Rico", "Virgin Islands", "Guam");
delete

Deletes items from a listbox. To delete all items:

$listbox->delete(0,'end');
get

Returns a list of elements within the specified range of indexes. For a list of all elements:

@items = $listbox->get(0,'end');
curselection

Returns a list of all currently selected elements in the listbox.

activate

Sets the specified item to be the active element.

bbox

Returns the location and dimensions of the bounding box surrounding the specified listbox element. The returned list contains four numbers representing (respectively) the x coordinate of the upper-left corner, the y coordinate of the upper-left corner, the width of the text in pixels, and the height of the text in pixels.

index

Converts a named index into a numeric one.

nearest

Gets the index of the listbox item nearest a given y coordinate.

see

Pages the listbox up or down to display the specified item.

selection

Manipulates the selected block of list items. The first argument can be any of:

anchor

Sets the anchor index to the specified index.

clear

Clears any selected list items in the specified range. For example, to clear all selections:

$listbox->selection('clear', 0, 'end');
includes

Returns 0 or 1 depending on whether the specified item is already selected:

$listbox->selection('includes', ...

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.