Create a listbox with the Listbox method.
You can then insert items into the listbox
using the insert method.
The standard configuration options that apply to$parentwidget->Listbox (options)
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 => modeDetermines how many items can be selected at once, as well
as key/mouse bindings. mode can be any of:
'single'Only one item can be selected at a time.
'browse'Only one item can be selected at a time. (Default).
'multiple'Multiple items can be selected at a time.
'extended'Multiple items can be selected at a time.
-setgrid => booleanTurns on gridding for the listbox. If the widget is resized, only complete lines and characters are displayed. Default is 0 (off).
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:
In addition to configure and cget, the following methods
are supported by Listbox:
insertAdds 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");
deleteDeletes items from a listbox. To delete all items:
$listbox->delete(0,'end');
getReturns a list of elements within the specified range of indexes. For a list of all elements:
@items = $listbox->get(0,'end');
curselectionReturns a list of all currently selected elements in the listbox.
activatebboxReturns 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.
indexnearestGets the index of the listbox item nearest to a given y coordinate.
seeselectionManipulates the selected block of list items. The first argument can be any of:
anchorSets the anchor index to the specified index.
clearClears any selected list items in the specified range. For example, to clear all selections:
$listbox->selection('clear', 0, 'end');includesReturns 0 or 1 depending on whether the specified item is
already selected.
$listbox->selection('includes', 'end');setSelects a range of items in the listbox.
$listbox->selection('set', 0, 'end');sizexviewManipulates the text in view. With no arguments, returns a
list of two numbers between 0 and 1, defining what portion of the
list text is currently hidden on the left and right sides,
respectively. With arguments, the function of xview
changes:
indexIf the first argument is an index, that position becomes the leftmost position in view.
movetoMoves the specified fraction of the listbox to the left of the visible portion.
scrollScrolls the text left or right by the specified number of units (characters, in this context) or pages. Used primarily as a callback to a scrollbar; pressing on an arrow would move by units (characters), and pressing on the trough would move by pages. The number is either 1 or -1, to move forwards or backwards, respectively.
yviewManipulates the text in view. With no arguments, returns a
list of two numbers between 0 and 1, defining what portion of the
list text is currently hidden
on the top and bottom,
respectively. With arguments, the function of yview
changes:
indexIf the first argument is an index, that position becomes the topmost position in view.
movetoMoves the specified fraction of the listbox to the top of the visible portion.
scrollScrolls the text up or down by the specified number of units (lines, in this context) or pages. Used primarily as a callback to a scrollbar; pressing on an arrow would move by units (lines), and pressing on the trough would move by pages. The number is either 1 or -1, to move forwards or backwards, respectively.