1listbox(n)                   Tk Built-In Commands                   listbox(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       listbox - Create and manipulate listbox widgets
9

SYNOPSIS

11       listbox pathName ?options?
12

STANDARD OPTIONS

14       -background           -borderwidth         -cursor
15       -disabledforeground   -exportselection     -font
16       -foreground           -highlightbackground -highlightcolor
17       -highlightthickness   -relief              -selectbackground
18       -selectborderwidth    -selectforeground    -setgrid
19       -takefocus            -xscrollcommand      -yscrollcommand
20
21       See the options manual entry for details on the standard options.
22

WIDGET-SPECIFIC OPTIONS

24       [-activestyle activeStyle]  Specifies  the  style  in which to draw the
25       active element.  This must be one of dotbox (show a focus  ring  around
26       the  active element), none (no special indication of active element) or
27       underline (underline the active element).  The default is underline  on
28       Windows,  and dotbox elsewhere.  [-height height] Specifies the desired
29       height for the window, in lines.  If zero or  less,  then  the  desired
30       height  for  the  window is made just large enough to hold all the ele‐
31       ments in the listbox.  [-listvariable listVariable] Specifies the  name
32       of  a  global variable.  The value of the variable is a list to be dis‐
33       played inside the widget; if the variable value changes then the widget
34       will automatically update itself to reflect the new value.  Attempts to
35       assign a variable with an invalid  list  value  to  -listvariable  will
36       cause an error.  Attempts to unset a variable in use as a -listvariable
37       will fail but will not  generate  an  error.   [-selectmode selectMode]
38       Specifies  one  of  several styles for manipulating the selection.  The
39       value of the option may be arbitrary, but the default  bindings  expect
40       it  to  be  either  single, browse, multiple, or extended;  the default
41       value is browse.  [-state state] Specifies one of two  states  for  the
42       listbox:   normal  or  disabled.  If the listbox is disabled then items
43       may not be inserted or deleted, items are drawn in  the  -disabledfore‐
44       ground color, and selection cannot be modified and is not shown (though
45       selection  information  is  retained).   [-width width]  Specifies  the
46       desired  width for the window in characters.  If the font does not have
47       a uniform width then the width of the character “0” is used  in  trans‐
48       lating from character units to screen units.  If zero or less, then the
49       desired width for the window is made just large enough to hold all  the
50       elements in the listbox.
51_________________________________________________________________
52

DESCRIPTION

54       The  listbox  command creates a new window (given by the pathName argu‐
55       ment)  and  makes  it  into  a  listbox  widget.   Additional  options,
56       described  above, may be specified on the command line or in the option
57       database to configure aspects of the listbox such as its colors,  font,
58       text,  and  relief.  The listbox command returns its pathName argument.
59       At the time this command is invoked, there  must  not  exist  a  window
60       named pathName, but pathName's parent must exist.
61
62       A  listbox  is  a widget that displays a list of strings, one per line.
63       When first created, a new listbox has no  elements.   Elements  may  be
64       added  or  deleted using widget commands described below.  In addition,
65       one or more elements may be selected as described below.  If a  listbox
66       is  exporting  its selection (see exportSelection option), then it will
67       observe the standard X11 protocols for handling the selection.  Listbox
68       selections  are  available  as  type STRING; the value of the selection
69       will be the text of the selected elements, with newlines separating the
70       elements.
71
72       It is not necessary for all the elements to be displayed in the listbox
73       window at once;  commands described below may be  used  to  change  the
74       view in the window.  Listboxes allow scrolling in both directions using
75       the standard xScrollCommand and yScrollCommand options.  They also sup‐
76       port scanning, as described below.
77

INDICES

79       Many  of  the widget commands for listboxes take one or more indices as
80       arguments.  An index specifies a particular element of the listbox,  in
81       any of the following ways:
82
83       number      Specifies  the element as a numerical index, where 0 corre‐
84                   sponds to the first element in the listbox.
85
86       active      Indicates the element that has the location  cursor.   This
87                   element will be displayed as specified by -activestyle when
88                   the listbox has the keyboard focus,  and  it  is  specified
89                   with the activate widget command.
90
91       anchor      Indicates  the anchor point for the selection, which is set
92                   with the selection anchor widget command.
93
94       end         Indicates the end of the listbox.  For most  commands  this
95                   refers  to  the  last element in the listbox, but for a few
96                   commands such as index and insert it refers to the  element
97                   just after the last one.
98
99       @x,y        Indicates  the element that covers the point in the listbox
100                   window specified by x and y (in pixel coordinates).  If  no
101                   element covers that point, then the closest element to that
102                   point is used.
103
104       In the widget command descriptions below, arguments named index, first,
105       and last always contain text indices in one of the above forms.
106

WIDGET COMMAND

108       The  listbox  command creates a new Tcl command whose name is pathName.
109       This command may be used to invoke various operations  on  the  widget.
110       It has the following general form:
111              pathName option ?arg arg ...?
112       Option  and  the args determine the exact behavior of the command.  The
113       following commands are possible for listbox widgets:
114
115       pathName activate index
116              Sets the active element to the one indicated by index.  If index
117              is outside the range of elements in the listbox then the closest
118              element is activated.  The active element is drawn as  specified
119              by  -activestyle  when  the  widget has the input focus, and its
120              index may be retrieved with the index active.
121
122       pathName bbox index
123              Returns a list of four numbers describing the  bounding  box  of
124              the  text in the element given by index.  The first two elements
125              of the list give the x and y coordinates of the upper-left  cor‐
126              ner  of the screen area covered by the text (specified in pixels
127              relative to the widget) and the last two elements give the width
128              and  height  of  the area, in pixels.  If no part of the element
129              given by index is visible on the screen, or if index refers to a
130              non-existent  element,  then  the result is an empty string;  if
131              the element is partially visible, the result gives the full area
132              of the element, including any parts that are not visible.
133
134       pathName cget option
135              Returns  the  current value of the configuration option given by
136              option.  Option may have any of the values accepted by the list‐
137              box command.
138
139       pathName configure ?option? ?value option value ...?
140              Query  or modify the configuration options of the widget.  If no
141              option is specified, returns a list describing all of the avail‐
142              able  options for pathName (see Tk_ConfigureInfo for information
143              on the format of this list).  If option  is  specified  with  no
144              value,  then the command returns a list describing the one named
145              option (this list will be identical to the corresponding sublist
146              of  the  value  returned  if no option is specified).  If one or
147              more option-value pairs are specified, then the command modifies
148              the  given widget option(s) to have the given value(s);  in this
149              case the command returns an empty string.  Option may  have  any
150              of the values accepted by the listbox command.
151
152       pathName curselection
153              Returns  a  list  containing the numerical indices of all of the
154              elements in the listbox that are currently selected.   If  there
155              are  no elements selected in the listbox then an empty string is
156              returned.
157
158       pathName delete first ?last?
159              Deletes one or more elements of the listbox.  First and last are
160              indices  specifying  the first and last elements in the range to
161              delete.  If last is not specified it defaults to first,  i.e.  a
162              single element is deleted.
163
164       pathName get first ?last?
165              If  last is omitted, returns the contents of the listbox element
166              indicated by first, or an empty string if first refers to a non-
167              existent  element.   If last is specified, the command returns a
168              list whose elements are all  of  the  listbox  elements  between
169              first  and last, inclusive.  Both first and last may have any of
170              the standard forms for indices.
171
172       pathName index index
173              Returns the integer index value that corresponds to  index.   If
174              index  is  end the return value is a count of the number of ele‐
175              ments in the listbox (not the index of the last element).
176
177       pathName insert index ?element element ...?
178              Inserts zero or more new elements in the list  just  before  the
179              element  given  by index.  If index is specified as end then the
180              new elements are added to the end of the list.  Returns an empty
181              string.
182
183       pathName itemcget index option
184              Returns the current value of the item configuration option given
185              by option. Option may have any of the  values  accepted  by  the
186              listbox itemconfigure command.
187
188       pathName itemconfigure index ?option? ?value? ?option value ...?
189              Query  or  modify  the  configuration  options of an item in the
190              listbox.  If no option is specified, returns a  list  describing
191              all  of the available options for the item (see Tk_ConfigureInfo
192              for information on the format of this list).  If option is spec‐
193              ified  with no value, then the command returns a list describing
194              the one named option (this list will be identical to the  corre‐
195              sponding  sublist  of  the value returned if no option is speci‐
196              fied).  If one or more option-value pairs  are  specified,  then
197              the  command  modifies  the  given  widget option(s) to have the
198              given value(s);  in this  case  the  command  returns  an  empty
199              string. The following options are currently supported for items:
200
201              -background color
202                     Color specifies the background color to use when display‐
203                     ing the item. It may have any of the  forms  accepted  by
204                     Tk_GetColor.
205
206              -foreground color
207                     Color specifies the foreground color to use when display‐
208                     ing the item. It may have any of the  forms  accepted  by
209                     Tk_GetColor.
210
211              -selectbackground color
212                     color specifies the background color to use when display‐
213                     ing the item while it is selected. It may have any of the
214                     forms accepted by Tk_GetColor.
215
216              -selectforeground color
217                     color specifies the foreground color to use when display‐
218                     ing the item while it is selected. It may have any of the
219                     forms accepted by Tk_GetColor.
220
221       pathName nearest y
222              Given  a  y-coordinate  within  the listbox window, this command
223              returns the index of the (visible) listbox  element  nearest  to
224              that y-coordinate.
225
226       pathName scan option args
227              This command is used to implement scanning on listboxes.  It has
228              two forms, depending on option:
229
230              pathName scan mark x y
231                     Records x and y and the current view in the listbox  win‐
232                     dow;   used  in  conjunction  with later scan dragto com‐
233                     mands.  Typically this command is associated with a mouse
234                     button press in the widget.  It returns an empty string.
235
236              pathName scan dragto x y.
237                     This  command computes the difference between its x and y
238                     arguments and the x and y arguments to the last scan mark
239                     command  for  the widget.  It then adjusts the view by 10
240                     times the difference in  coordinates.   This  command  is
241                     typically associated with mouse motion events in the wid‐
242                     get, to produce the effect of dragging the list  at  high
243                     speed  through  the window.  The return value is an empty
244                     string.
245
246       pathName see index
247              Adjust the view in the listbox so  that  the  element  given  by
248              index  is  visible.   If the element is already visible then the
249              command has no effect; if the element is near one  edge  of  the
250              window  then  the listbox scrolls to bring the element into view
251              at the edge;  otherwise the listbox scrolls to center  the  ele‐
252              ment.
253
254       pathName selection option arg
255              This  command  is used to adjust the selection within a listbox.
256              It has several forms, depending on option:
257
258              pathName selection anchor index
259                     Sets the selection anchor to the element given by  index.
260                     If index refers to a non-existent element, then the clos‐
261                     est element is used.  The selection anchor is the end  of
262                     the  selection  that is fixed while dragging out a selec‐
263                     tion with the mouse.  The index anchor  may  be  used  to
264                     refer to the anchor element.
265
266              pathName selection clear first ?last?
267                     If any of the elements between first and last (inclusive)
268                     are selected, they are deselected.  The  selection  state
269                     is not changed for elements outside this range.
270
271              pathName selection includes index
272                     Returns  1 if the element indicated by index is currently
273                     selected, 0 if it is not.
274
275              pathName selection set first ?last?
276                     Selects all of the elements in the  range  between  first
277                     and  last,  inclusive,  without  affecting  the selection
278                     state of elements outside that range.
279
280       pathName size
281              Returns a decimal string indicating the total number of elements
282              in the listbox.
283
284       pathName xview args
285              This command is used to query and change the horizontal position
286              of the information in the widget's window.  It can take  any  of
287              the following forms:
288
289              pathName xview
290                     Returns  a list containing two elements.  Each element is
291                     a real fraction between 0 and 1;  together they  describe
292                     the  horizontal  span that is visible in the window.  For
293                     example, if the first element is .2 and the  second  ele‐
294                     ment  is  .6,  20% of the listbox's text is off-screen to
295                     the left, the middle 40% is visible in  the  window,  and
296                     40%  of  the  text is off-screen to the right.  These are
297                     the same values passed to scrollbars via the -xscrollcom‐
298                     mand option.
299
300              pathName xview index
301                     Adjusts  the  view  in  the  window so that the character
302                     position given by index is displayed at the left edge  of
303                     the window.  Character positions are defined by the width
304                     of the character 0.
305
306              pathName xview moveto fraction
307                     Adjusts the view in the window so that  fraction  of  the
308                     total  width  of  the  listbox  text is off-screen to the
309                     left.  fraction must be a fraction between 0 and 1.
310
311              pathName xview scroll number what
312                     This command shifts the view in the window left or  right
313                     according to number and what.  Number must be an integer.
314                     What must be either units or pages or an abbreviation  of
315                     one of these.  If what is units, the view adjusts left or
316                     right by number character units (the width of the 0 char‐
317                     acter)  on  the  display;   if  it is pages then the view
318                     adjusts by number screenfuls.  If number is negative then
319                     characters  farther to the left become visible;  if it is
320                     positive then characters farther to the right become vis‐
321                     ible.
322
323       pathName yview ?args?
324              This  command  is used to query and change the vertical position
325              of the text in the widget's window.  It can take any of the fol‐
326              lowing forms:
327
328              pathName yview
329                     Returns a list containing two elements, both of which are
330                     real fractions between 0 and 1.  The first element  gives
331                     the  position  of  the  listbox element at the top of the
332                     window, relative to the listbox as a whole (0.5 means  it
333                     is halfway through the listbox, for example).  The second
334                     element gives the position of the  listbox  element  just
335                     after the last one in the window, relative to the listbox
336                     as a whole.  These are the same values passed to  scroll‐
337                     bars via the -yscrollcommand option.
338
339              pathName yview index
340                     Adjusts  the view in the window so that the element given
341                     by index is displayed at the top of the window.
342
343              pathName yview moveto fraction
344                     Adjusts the view in the window so that the element  given
345                     by  fraction  appears at the top of the window.  Fraction
346                     is a fraction between 0 and 1;   0  indicates  the  first
347                     element  in  the listbox, 0.33 indicates the element one-
348                     third the way through the listbox, and so on.
349
350              pathName yview scroll number what
351                     This command adjusts the view in the window  up  or  down
352                     according to number and what.  Number must be an integer.
353                     What must be either units or pages.  If  what  is  units,
354                     the  view  adjusts  up or down by number lines;  if it is
355                     pages then the view adjusts  by  number  screenfuls.   If
356                     number  is negative then earlier elements become visible;
357                     if it is positive then later elements become visible.
358

DEFAULT BINDINGS

360       Tk automatically creates class bindings for listboxes  that  give  them
361       Motif-like  behavior.   Much of the behavior of a listbox is determined
362       by its selectMode option, which selects one of  four  ways  of  dealing
363       with the selection.
364
365       If  the  selection mode is single or browse, at most one element can be
366       selected in the listbox at once.  In both modes, clicking button  1  on
367       an element selects it and deselects any other selected item.  In browse
368       mode it is also possible to drag the selection with button 1.  On  but‐ │
369       ton  1,  the  listbox will also take focus if it has a normal state and │
370       -takefocus is true.
371
372       If the selection mode is multiple or extended, any number  of  elements
373       may  be  selected at once, including discontiguous ranges.  In multiple
374       mode, clicking button 1 on an element toggles its selection state with‐
375       out  affecting any other elements.  In extended mode, pressing button 1
376       on an element selects it,  deselects  everything  else,  and  sets  the
377       anchor  to the element under the mouse;  dragging the mouse with button
378       1 down extends the selection to include all the  elements  between  the
379       anchor and the element under the mouse, inclusive.
380
381       Most people will probably want to use browse mode for single selections
382       and extended mode for multiple selections; the other modes appear to be
383       useful only in special situations.
384
385       Any  time  the  selection  changes  in  the  listbox, the virtual event
386       <<ListboxSelect>> will be generated.  It is easiest  to  bind  to  this
387       event to be made aware of any changes to listbox selection.
388
389       In addition to the above behavior, the following additional behavior is
390       defined by the default bindings:
391
392       [1]    In extended mode, the selected range can be adjusted by pressing
393              button  1  with the Shift key down:  this modifies the selection
394              to consist of the elements between the anchor  and  the  element
395              under  the  mouse,  inclusive.   The un-anchored end of this new
396              selection can also be dragged with the button down.
397
398       [2]    In extended mode, pressing button 1 with the  Control  key  down
399              starts  a  toggle  operation:  the  anchor is set to the element
400              under the mouse, and  its  selection  state  is  reversed.   The
401              selection  state of other elements is not changed.  If the mouse
402              is dragged with button 1 down, then the selection state  of  all
403              elements  between  the anchor and the element under the mouse is
404              set to match that of the anchor element;  the selection state of
405              all  other elements remains what it was before the toggle opera‐
406              tion began.
407
408       [3]    If the mouse leaves the listbox window with button 1  down,  the
409              window  scrolls  away from the mouse, making information visible
410              that used to be off-screen  on  the  side  of  the  mouse.   The
411              scrolling  continues  until  the mouse re-enters the window, the
412              button is released, or the end of the listbox is reached.
413
414       [4]    Mouse button 2 may be used for scanning.  If it is  pressed  and
415              dragged  over  the  listbox, the contents of the listbox drag at
416              high speed in the direction the mouse moves.
417
418       [5]    If the Up or Down key is pressed, the  location  cursor  (active
419              element) moves up or down one element.  If the selection mode is
420              browse or extended then the new active element is also  selected
421              and all other elements are deselected.  In extended mode the new
422              active element becomes the selection anchor.
423
424       [6]    In extended mode, Shift-Up and Shift-Down move the location cur‐
425              sor  (active element) up or down one element and also extend the
426              selection to that element in a fashion similar to dragging  with
427              mouse button 1.
428
429       [7]    The  Left  and Right keys scroll the listbox view left and right
430              by the width of the character 0.  Control-Left and Control-Right
431              scroll  the listbox view left and right by the width of the win‐
432              dow.  Control-Prior and Control-Next also scroll left and  right
433              by the width of the window.
434
435       [8]    The  Prior  and Next keys scroll the listbox view up and down by
436              one page (the height of the window).
437
438       [9]    The Home and End keys scroll the  listbox  horizontally  to  the
439              left and right edges, respectively.
440
441       [10]   Control-Home  sets  the  location cursor to the first element in
442              the listbox, selects that element, and deselects everything else
443              in the listbox.
444
445       [11]   Control-End  sets the location cursor to the last element in the
446              listbox, selects that element, and deselects everything else  in
447              the listbox.
448
449       [12]   In  extended  mode,  Control-Shift-Home extends the selection to
450              the first element in the listbox and  Control-Shift-End  extends
451              the selection to the last element.
452
453       [13]   In  multiple  mode, Control-Shift-Home moves the location cursor
454              to the first element in the listbox and Control-Shift-End  moves
455              the location cursor to the last element.
456
457       [14]   The  space and Select keys make a selection at the location cur‐
458              sor (active element) just as if mouse button 1 had been  pressed
459              over this element.
460
461       [15]   In  extended  mode,  Control-Shift-space and Shift-Select extend
462              the selection to the active element just as if button 1 had been
463              pressed with the Shift key down.
464
465       [16]   In  extended mode, the Escape key cancels the most recent selec‐
466              tion and restores all the elements  in  the  selected  range  to
467              their previous selection state.
468
469       [17]   Control-slash selects everything in the widget, except in single
470              and browse modes, in which case it selects  the  active  element
471              and deselects everything else.
472
473       [18]   Control-backslash  deselects everything in the widget, except in
474              browse mode where it has no effect.
475
476       [19]   The F16 key (labelled Copy on many Sun workstations)  or  Meta-w
477              copies the selection in the widget to the clipboard, if there is
478              a selection.
479
480       The behavior of listboxes can be changed by defining new  bindings  for
481       individual widgets or by redefining the class bindings.
482

SEE ALSO

484       ttk_treeview(n)
485

KEYWORDS

487       listbox, widget
488
489
490
491Tk                                    8.4                           listbox(n)
Impressum