The Listbox Widget
Create a listbox with the Listbox
method.
You can then insert items into the listbox
using the insert
method.
$parentwidget->Listbox (options)
The standard configuration options that apply to Listbox
are:
-background
,
-bg
,
-borderwidth
,
-bd
,
-cursor
,
-exportselection
,
-font
,
-foreground
,
-fg
,
-height
,
-highlightbackground
,
-highlightcolor
,
-highlightthickness
,
-relief
,
-selectbackground
,
-selectborderwidth
,
-selectforeground
,
-takefocus
,
-width
,
-xscrollcommand
,
and
-yscrollcommand
.
Other options are:
-
-selectmode =>
mode
Determines how many items can be selected at once, as well as key/mouse bindings.
mode
can be any of:-
-setgrid =>
boolean
Turns on gridding for the listbox. If the widget is resized, only complete lines and characters are displayed. Default is 0 (off).
Listbox Indexes
In a Listbox widget, several indexes are defined to identify positions in the listbox, for use by the methods used for retrieving or manipulating listbox entries. These indexes are:
-
n
An integer representing a position in the list, with 0 as the first item.
-
active
The item with the keyboard focus.
-
anchor
The anchored position.
-
end
The last element in the listbox.
-
@
x,y
The listbox item containing the specified x,y coordinate.
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", ...
Get Perl in a Nutshell 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.