Tcl8.6.10/Tk8.6.10 Documentation > Tk Commands > listbox
Tcl/Tk Applications | Tcl Commands | Tk Commands | [incr Tcl] Package Commands | SQLite3 Package Commands | TDBC Package Commands | tdbc::mysql Package Commands | tdbc::odbc Package Commands | tdbc::postgres Package Commands | tdbc::sqlite3 Package Commands | Thread Package Commands | Tcl C API | Tk C API | [incr Tcl] Package C API | TDBC Package C API
- NAME
- listbox — Create and manipulate 'listbox' item list widgets
- SYNOPSIS
- STANDARD OPTIONS
- -background or -bg, background, Background
- -borderwidth or -bd, borderWidth, BorderWidth
- -cursor, cursor, Cursor
- -disabledforeground, disabledForeground, DisabledForeground
- -exportselection, exportSelection, ExportSelection
- -font, font, Font
- -foreground or -fg, foreground, Foreground
- -highlightbackground, highlightBackground, HighlightBackground
- -highlightcolor, highlightColor, HighlightColor
- -highlightthickness, highlightThickness, HighlightThickness
- -justify, justify, Justify
- -relief, relief, Relief
- -selectbackground, selectBackground, Foreground
- -selectborderwidth, selectBorderWidth, BorderWidth
- -selectforeground, selectForeground, Background
- -setgrid, setGrid, SetGrid
- -takefocus, takeFocus, TakeFocus
- -xscrollcommand, xScrollCommand, ScrollCommand
- -yscrollcommand, yScrollCommand, ScrollCommand
- -borderwidth or -bd, borderWidth, BorderWidth
- WIDGET-SPECIFIC OPTIONS
- -activestyle, activeStyle, ActiveStyle
- -height, height, Height
- -listvariable, listVariable, Variable
- -selectmode, selectMode, SelectMode
- -state, state, State
- -width, width, Width
- -height, height, Height
- DESCRIPTION
- INDICES
- WIDGET COMMAND
- DEFAULT BINDINGS
- SEE ALSO
- KEYWORDS
NAME
listbox — Create and manipulate 'listbox' item list widgetsSYNOPSIS
listbox pathName ?options?STANDARD OPTIONS
- -background or -bg, background, Background
- -borderwidth or -bd, borderWidth, BorderWidth
- -cursor, cursor, Cursor
- -disabledforeground, disabledForeground, DisabledForeground
- -exportselection, exportSelection, ExportSelection
- -font, font, Font
- -foreground or -fg, foreground, Foreground
- -highlightbackground, highlightBackground, HighlightBackground
- -highlightcolor, highlightColor, HighlightColor
- -highlightthickness, highlightThickness, HighlightThickness
- -justify, justify, Justify
- -relief, relief, Relief
- -selectbackground, selectBackground, Foreground
- -selectborderwidth, selectBorderWidth, BorderWidth
- -selectforeground, selectForeground, Background
- -setgrid, setGrid, SetGrid
- -takefocus, takeFocus, TakeFocus
- -xscrollcommand, xScrollCommand, ScrollCommand
- -yscrollcommand, yScrollCommand, ScrollCommand
- -borderwidth or -bd, borderWidth, BorderWidth
WIDGET-SPECIFIC OPTIONS
- Command-Line Name: -activestyle
- Database Name: activeStyle
- Database Class: ActiveStyle
- Database Name: activeStyle
- Specifies the style in which to draw the active element. This must be one of dotbox (show a focus ring around the active element), none (no special indication of active element) or underline (underline the active element). The default is underline on Windows, and dotbox elsewhere.
- Command-Line Name: -height
- Database Name: height
- Database Class: Height
- Database Name: height
- Specifies the desired height for the window, in lines. If zero or less, then the desired height for the window is made just large enough to hold all the elements in the listbox.
- Command-Line Name: -listvariable
- Database Name: listVariable
- Database Class: Variable
- Database Name: listVariable
- Specifies the name of a global variable. The value of the variable is a list to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value. Attempts to assign a variable with an invalid list value to -listvariable will cause an error. Attempts to unset a variable in use as a -listvariable will fail but will not generate an error.
- Command-Line Name: -selectmode
- Database Name: selectMode
- Database Class: SelectMode
- Database Name: selectMode
- Specifies one of several styles for manipulating the selection. The value of the option may be arbitrary, but the default bindings expect it to be either single, browse, multiple, or extended; the default value is browse.
- Command-Line Name: -state
- Database Name: state
- Database Class: State
- Database Name: state
- Specifies one of two states for the listbox: normal or disabled. If the listbox is disabled then items may not be inserted or deleted, items are drawn in the -disabledforeground color, and selection cannot be modified and is not shown (though selection information is retained).
- Command-Line Name: -width
- Database Name: width
- Database Class: Width
- Database Name: width
- Specifies the desired width for the window in characters. If the font does not have a uniform width then the width of the character “0” is used in translating from character units to screen units. If zero or less, then the desired width for the window is made just large enough to hold all the elements in the listbox.
DESCRIPTION
The listbox command creates a new window (given by the pathName argument) and makes it into a listbox widget. Additional options, described above, may be specified on the command line or in the option database to configure aspects of the listbox such as its colors, font, text, and relief. The listbox command returns its pathName argument. At the time this command is invoked, there must not exist a window named pathName, but pathName's parent must exist.A listbox is a widget that displays a list of strings, one per line. When first created, a new listbox has no elements. Elements may be added or deleted using widget commands described below. In addition, one or more elements may be selected as described below. If a listbox is exporting its selection (see -exportselection option), then it will observe the standard X11 protocols for handling the selection. Listbox selections are available as type STRING; the value of the selection will be the text of the selected elements, with newlines separating the elements.
It is not necessary for all the elements to be displayed in the listbox window at once; commands described below may be used to change the view in the window. Listboxes allow scrolling in both directions using the standard -xscrollcommand and -yscrollcommand options. They also support scanning, as described below.
INDICES
Many of the widget commands for listboxes take one or more indices as arguments. An index specifies a particular element of the listbox, in any of the following ways:
- number
- Specifies the element as a numerical index, where 0 corresponds to the first element in the listbox.
- active
- Indicates the element that has the location cursor. This element will be displayed as specified by -activestyle when the listbox has the keyboard focus, and it is specified with the activate widget command.
- anchor
- Indicates the anchor point for the selection, which is set with the selection anchor widget command.
- end
- Indicates the end of the listbox. For most commands this refers to the last element in the listbox, but for a few commands such as index and insert it refers to the element just after the last one.
- @x,y
- Indicates the element that covers the point in the listbox window specified by x and y (in pixel coordinates). If no element covers that point, then the closest element to that point is used.
In the widget command descriptions below, arguments named index, first, and last always contain text indices in one of the above forms.
WIDGET COMMAND
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:
DEFAULT BINDINGS
Tk automatically creates class bindings for listboxes that give them Motif-like behavior. Much of the behavior of a listbox is determined by its -selectmode option, which selects one of four ways of dealing with the selection.If the selection mode is single or browse, at most one element can be selected in the listbox at once. In both modes, clicking button 1 on an element selects it and deselects any other selected item. In browse mode it is also possible to drag the selection with button 1. On button 1, the listbox will also take focus if it has a normal state.
If the selection mode is multiple or extended, any number of elements may be selected at once, including discontiguous ranges. In multiple mode, clicking button 1 on an element toggles its selection state without affecting any other elements. In extended mode, pressing button 1 on an element selects it, deselects everything else, and sets the anchor to the element under the mouse; dragging the mouse with button 1 down extends the selection to include all the elements between the anchor and the element under the mouse, inclusive.
Most people will probably want to use browse mode for single selections and extended mode for multiple selections; the other modes appear to be useful only in special situations.
Any time the set of selected item(s) in the listbox is updated by the user through the keyboard or mouse, the virtual event <<ListboxSelect>> will be generated. This virtual event will not be generated when adjusting the selection with the pathName selection command. It is easiest to bind to this event to be made aware of any user changes to listbox selection.
In addition to the above behavior, the following additional behavior is defined by the default bindings:
- In extended mode, the selected range can be adjusted by pressing button 1 with the Shift key down: this modifies the selection to consist of the elements between the anchor and the element under the mouse, inclusive. The un-anchored end of this new selection can also be dragged with the button down.
- In extended mode, pressing button 1 with the Control key down starts a toggle operation: the anchor is set to the element under the mouse, and its selection state is reversed. The selection state of other elements is not changed. If the mouse is dragged with button 1 down, then the selection state of all elements between the anchor and the element under the mouse is set to match that of the anchor element; the selection state of all other elements remains what it was before the toggle operation began.
- If the mouse leaves the listbox window with button 1 down, the window scrolls away from the mouse, making information visible that used to be off-screen on the side of the mouse. The scrolling continues until the mouse re-enters the window, the button is released, or the end of the listbox is reached.
- Mouse button 2 may be used for scanning. If it is pressed and dragged over the listbox, the contents of the listbox drag at high speed in the direction the mouse moves.
- If the Up or Down key is pressed, the location cursor (active element) moves up or down one element. If the selection mode is browse or extended then the new active element is also selected and all other elements are deselected. In extended mode the new active element becomes the selection anchor.
- In extended mode, Shift-Up and Shift-Down move the location cursor (active element) up or down one element and also extend the selection to that element in a fashion similar to dragging with mouse button 1.
- The Left and Right keys scroll the listbox view left and right by the width of the character 0. Control-Left and Control-Right scroll the listbox view left and right by the width of the window. Control-Prior and Control-Next also scroll left and right by the width of the window.
- The Prior and Next keys scroll the listbox view up and down by one page (the height of the window).
- The Home and End keys scroll the listbox horizontally to the left and right edges, respectively.
- Control-Home sets the location cursor to the first element in the listbox, selects that element, and deselects everything else in the listbox.
- Control-End sets the location cursor to the last element in the listbox, selects that element, and deselects everything else in the listbox.
- In extended mode, Control-Shift-Home extends the selection to the first element in the listbox and Control-Shift-End extends the selection to the last element.
- In multiple mode, Control-Shift-Home moves the location cursor to the first element in the listbox and Control-Shift-End moves the location cursor to the last element.
- The space and Select keys make a selection at the location cursor (active element) just as if mouse button 1 had been pressed over this element.
- In extended mode, Control-Shift-space and Shift-Select extend the selection to the active element just as if button 1 had been pressed with the Shift key down.
- In extended mode, the Escape key cancels the most recent selection and restores all the elements in the selected range to their previous selection state.
- Control-slash selects everything in the widget, except in single and browse modes, in which case it selects the active element and deselects everything else.
- Control-backslash deselects everything in the widget, except in browse mode where it has no effect.
- The F16 key (labelled Copy on many Sun workstations) or Meta-w copies the selection in the widget to the clipboard, if there is a selection.
The behavior of listboxes can be changed by defining new bindings for individual widgets or by redefining the class bindings.
SEE ALSO
ttk::treeviewKEYWORDS
listbox, widgetCopyright © 1994-1997 Sun Microsystems, Inc.