A Listbox's Arguments
The listbox command creates a new Tcl command whose
name is pathName. This
command may be used to invoke various
operations on the widget. It has the following general form:
pathName option ?arg arg ...?
Option and the args
determine the exact behavior of the command. The following
commands are possible for listbox widgets:
- pathName :configure ?option? ?value option value ...?
- Query or modify the configuration options of the widget.
If no option is specified, returns a list describing all of
the available options for pathName (see Tk_ConfigureInfo for
information on the format of this list). If option is specified
with no value, then the command returns a list describing the
one named option (this list will be identical to the corresponding
sublist of the value returned if no option is specified). If
one or more option:value pairs are specified, then the command
modifies the given widget option(s) to have the given value(s); in
this case the command returns an empty string.
Option may have any of the values accepted by the listbox
- pathName :curselection
- Returns a list containing the indices of
all of the elements in the listbox that are currently selected.
If there are no elements selected in the listbox then an empty
string is returned.
- pathName :delete first ?last?
- Delete one or more elements of the listbox. First and last
give the integer indices of the first and last elements in the range
to be deleted. If last isn't specified it defaults to
first, i.e. a single element is deleted. An index of
0 corresponds to the first element in the listbox. Either
first or last may be specified as end, in which
case it refers to the last element of the listbox. This command
returns an empty string
- pathName :get index
- Return the contents of the listbox element indicated by index.
Index must be a non-negative integer (0 corresponds to
the first element in the listbox), or it may also be specified as
end to indicate the last element in the listbox.
- pathName :insert index ?element element ...?
- Insert zero or more new elements in the list just before the
element given by index. If index is specified as
end then the new elements are added to the end of the
list. Returns an empty string.
- pathName :nearest y
- Given a y-coordinate within the listbox window, this command returns
the index of the (visible) listbox element nearest to that y-coordinate.
- pathName :scan option args
- This command is used to implement scanning on listboxes. It has
two forms, depending on option:
- pathName :scan :mark x y
- Records x and y and the current view in the listbox
window; used in conjunction with later scan dragto commands.
Typically this command is associated with a mouse button press in
the widget. It returns an empty string.
- pathName :scan :dragto x y.
- This command computes the difference between its x and y
arguments and the x and y arguments to the last
scan mark command for the widget.
It then adjusts the view by 10 times the
difference in coordinates. This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the list at high speed through the window. The return
value is an empty string.
- pathName :select option arg
- This command is used to adjust the selection within a listbox. It
has several forms, depending on option. In all of the forms
the index end refers to the last element in the listbox.
- pathName :select :adjust index
- Locate the end of the selection nearest to the element given by
index, and adjust that end of the selection to be at index
(i.e including but not going beyond index). The other
end of the selection is made the anchor point for future
select to commands. If the selection
isn't currently in the listbox, then this command is identical to
the select from widget command.
Returns an empty string.
- pathName :select :clear
- If the selection is in this listbox then it is cleared so that
none of the listbox's elements are selected anymore.
- pathName :select :from index
- Set the selection to consist of element index, and make
index the anchor point for future select to widget
commands. Returns an empty string.
- pathName :select :to index
- Set the selection to consist of the elements from the anchor
point to element index, inclusive. The anchor point is
determined by the most recent select from or select adjust
command in this widget. If the selection isn't in this widget,
this command is identical to select from.
Returns an empty string.
- pathName :size
- Returns a decimal string indicating the total number of elements
in the listbox.
- pathName :xview index
- Adjust the view in the listbox so that character position index
is displayed at the left edge of the widget.
Returns an empty string.
- pathName :yview index
- Adjust the view in the listbox so that element index is
displayed at the top of the widget.
If index is specified as end it indicates the last
element of the listbox. Returns an empty string.