| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| 2 |
<html> |
| 3 |
<!-- Created by GNU Texinfo 6.7, http://www.gnu.org/software/texinfo/ --> |
| 4 |
<head> |
| 5 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
| 6 |
<title>listbox (GCL TK Manual)</title> |
| 7 |
|
| 8 |
<meta name="description" content="listbox (GCL TK Manual)"> |
| 9 |
<meta name="keywords" content="listbox (GCL TK Manual)"> |
| 10 |
<meta name="resource-type" content="document"> |
| 11 |
<meta name="distribution" content="global"> |
| 12 |
<meta name="Generator" content="makeinfo"> |
| 13 |
<link href="index.html" rel="start" title="Top"> |
| 14 |
<link href="wm.html#SEC_Contents" rel="contents" title="Table of Contents"> |
| 15 |
<link href="Widgets.html" rel="up" title="Widgets"> |
| 16 |
<link href="scale.html" rel="next" title="scale"> |
| 17 |
<link href="button.html" rel="prev" title="button"> |
| 18 |
<style type="text/css"> |
| 19 |
<!-- |
| 20 |
a.summary-letter {text-decoration: none} |
| 21 |
blockquote.indentedblock {margin-right: 0em} |
| 22 |
div.display {margin-left: 3.2em} |
| 23 |
div.example {margin-left: 3.2em} |
| 24 |
div.lisp {margin-left: 3.2em} |
| 25 |
kbd {font-style: oblique} |
| 26 |
pre.display {font-family: inherit} |
| 27 |
pre.format {font-family: inherit} |
| 28 |
pre.menu-comment {font-family: serif} |
| 29 |
pre.menu-preformatted {font-family: serif} |
| 30 |
span.nolinebreak {white-space: nowrap} |
| 31 |
span.roman {font-family: initial; font-weight: normal} |
| 32 |
span.sansserif {font-family: sans-serif; font-weight: normal} |
| 33 |
ul.no-bullet {list-style: none} |
| 34 |
--> |
| 35 |
</style> |
| 36 |
|
| 37 |
|
| 38 |
</head> |
| 39 |
|
| 40 |
<body lang="en"> |
| 41 |
<span id="listbox"></span><div class="header"> |
| 42 |
<p> |
| 43 |
Next: <a href="scale.html" accesskey="n" rel="next">scale</a>, Previous: <a href="button.html" accesskey="p" rel="prev">button</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 44 |
</div> |
| 45 |
<hr> |
| 46 |
<span id="listbox-1"></span><h3 class="section">2.2 listbox</h3> |
| 47 |
|
| 48 |
<p>listbox \- Create and manipulate listbox widgets |
| 49 |
</p><span id="Synopsis-1"></span><h4 class="unnumberedsubsec">Synopsis</h4> |
| 50 |
<p><b>listbox</b><i> </i><i>pathName </i><span class="roman">?</span><i>options</i>? |
| 51 |
</p><span id="Standard-Options-1"></span><h4 class="unnumberedsubsec">Standard Options</h4> |
| 52 |
|
| 53 |
|
| 54 |
<div class="example"> |
| 55 |
<pre class="example">background foreground selectBackground xScrollCommand |
| 56 |
borderWidth font selectBorderWidth yScrollCommand |
| 57 |
cursor geometry selectForeground |
| 58 |
exportSelection relief setGrid |
| 59 |
</pre></div> |
| 60 |
|
| 61 |
|
| 62 |
<p>See <a href="options.html">options</a>, for more information. |
| 63 |
</p><span id="Arguments-for-Listbox"></span><h4 class="unnumberedsubsec">Arguments for Listbox</h4> |
| 64 |
|
| 65 |
|
| 66 |
<p>None. |
| 67 |
</p> |
| 68 |
<span id="Description-1"></span><h4 class="unnumberedsubsec">Description</h4> |
| 69 |
|
| 70 |
<p>The <b>listbox</b> command creates a new window (given by the |
| 71 |
<i>pathName</i> argument) and makes it into a listbox widget. |
| 72 |
Additional |
| 73 |
options, described above, may be specified on the command line |
| 74 |
or in the option database |
| 75 |
to configure aspects of the listbox such as its colors, font, |
| 76 |
text, and relief. The <b>listbox</b> command returns its |
| 77 |
<i>pathName</i> argument. At the time this command is invoked, |
| 78 |
there must not exist a window named <i>pathName</i>, but |
| 79 |
<i>pathName</i>’s parent must exist. |
| 80 |
</p> |
| 81 |
<p>A listbox is a widget that displays a list of strings, one per line. |
| 82 |
When first created, a new listbox has no elements in its list. |
| 83 |
Elements may be added or deleted using widget commands described |
| 84 |
below. In addition, one or more elements may be selected as described |
| 85 |
below. |
| 86 |
If a listbox is exporting its selection (see <b>exportSelection</b> |
| 87 |
option), then it will observe the standard X11 protocols |
| 88 |
for handling the selection; listbox selections are available |
| 89 |
as type <b>STRING</b>, consisting of a Tcl list with one entry |
| 90 |
for each selected element. |
| 91 |
</p> |
| 92 |
<p>For large lists only a subset of the list elements will be |
| 93 |
displayed in the listbox window at once; commands described below |
| 94 |
may be used to change the view in the window. Listboxes allow |
| 95 |
scrolling in both directions using the standard <b>xScrollCommand</b> |
| 96 |
and <b>yScrollCommand</b> options. |
| 97 |
They also support scanning, as described below. |
| 98 |
</p> |
| 99 |
<span id="A-Listbox_0027s-Arguments"></span><h4 class="unnumberedsubsec">A Listbox’s Arguments</h4> |
| 100 |
|
| 101 |
<p>The <b>listbox</b> command creates a new Tcl command whose |
| 102 |
name is <i>pathName</i>. This |
| 103 |
command may be used to invoke various |
| 104 |
operations on the widget. It has the following general form: |
| 105 |
</p> |
| 106 |
<div class="example"> |
| 107 |
<pre class="example"><i>pathName option </i><span class="roman">?</span><i>arg arg ...</i>? |
| 108 |
</pre></div> |
| 109 |
|
| 110 |
<p><i>Option</i><span class="roman"> and the </span><i>arg</i>s |
| 111 |
determine the exact behavior of the command. The following |
| 112 |
commands are possible for listbox widgets: |
| 113 |
</p> |
| 114 |
<dl compact="compact"> |
| 115 |
<dt><i>pathName </i><b>:configure</b><span class="roman"> ?</span><i>option</i><span class="roman">? ?</span><i>value option value ...</i>?</dt> |
| 116 |
<dd><p>Query or modify the configuration options of the widget. |
| 117 |
If no <i>option</i> is specified, returns a list describing all of |
| 118 |
the available options for <i>pathName</i><span class="roman"> (see </span><b>Tk_ConfigureInfo</b> for |
| 119 |
information on the format of this list). If <i>option</i> is specified |
| 120 |
with no <i>value</i>, then the command returns a list describing the |
| 121 |
one named option (this list will be identical to the corresponding |
| 122 |
sublist of the value returned if no <i>option</i> is specified). If |
| 123 |
one or more <i>option:value</i> pairs are specified, then the command |
| 124 |
modifies the given widget option(s) to have the given value(s); in |
| 125 |
this case the command returns an empty string. |
| 126 |
<i>Option</i><span class="roman"> may have any of the values accepted by the </span><b>listbox</b> |
| 127 |
command. |
| 128 |
</p></dd> |
| 129 |
<dt><i>pathName </i><b>:curselection</b></dt> |
| 130 |
<dd><p>Returns a list containing the indices of |
| 131 |
all of the elements in the listbox that are currently selected. |
| 132 |
If there are no elements selected in the listbox then an empty |
| 133 |
string is returned. |
| 134 |
</p></dd> |
| 135 |
<dt><i>pathName </i><b>:delete </b><i>first </i><span class="roman">?</span><i>last</i>?</dt> |
| 136 |
<dd><p>Delete one or more elements of the listbox. <i>First</i><span class="roman"> and </span><i>last</i> |
| 137 |
give the integer indices of the first and last elements in the range |
| 138 |
to be deleted. If <i>last</i> isn’t specified it defaults to |
| 139 |
<i>first</i>, i.e. a single element is deleted. An index of |
| 140 |
<b>0</b> corresponds to the first element in the listbox. Either |
| 141 |
<i>first</i><span class="roman"> or </span><i>last</i><span class="roman"> may be specified as </span><b>end</b>, in which |
| 142 |
case it refers to the last element of the listbox. This command |
| 143 |
returns an empty string |
| 144 |
</p></dd> |
| 145 |
<dt><i>pathName </i><b>:get </b><i>index</i></dt> |
| 146 |
<dd><p>Return the contents of the listbox element indicated by <i>index</i>. |
| 147 |
<i>Index</i> must be a non-negative integer (0 corresponds to |
| 148 |
the first element in the listbox), or it may also be specified as |
| 149 |
<b>end</b> to indicate the last element in the listbox. |
| 150 |
</p></dd> |
| 151 |
<dt><i>pathName </i><b>:insert </b><i>index </i><span class="roman">?</span><i>element element ...</i>?</dt> |
| 152 |
<dd><p>Insert zero or more new elements in the list just before the |
| 153 |
element given by <i>index</i><span class="roman">. If </span><i>index</i> is specified as |
| 154 |
<b>end</b> then the new elements are added to the end of the |
| 155 |
list. Returns an empty string. |
| 156 |
</p></dd> |
| 157 |
<dt><i>pathName </i><b>:nearest </b><i>y</i></dt> |
| 158 |
<dd><p>Given a y-coordinate within the listbox window, this command returns |
| 159 |
the index of the (visible) listbox element nearest to that y-coordinate. |
| 160 |
</p></dd> |
| 161 |
<dt><i>pathName </i><b>:scan</b><span class="roman"> </span><i>option args</i></dt> |
| 162 |
<dd><p>This command is used to implement scanning on listboxes. It has |
| 163 |
two forms, depending on <i>option</i>: |
| 164 |
</p><dl compact="compact"> |
| 165 |
<dt><i>pathName </i><b>:scan :mark </b><i>x y</i></dt> |
| 166 |
<dd><p>Records <i>x</i><span class="roman"> and </span><i>y</i> and the current view in the listbox |
| 167 |
window; used in conjunction with later <b>scan dragto</b> commands. |
| 168 |
Typically this command is associated with a mouse button press in |
| 169 |
the widget. It returns an empty string. |
| 170 |
</p></dd> |
| 171 |
<dt><i>pathName </i><b>:scan :dragto </b><i>x y</i>.</dt> |
| 172 |
<dd><p>This command computes the difference between its <i>x</i><span class="roman"> and </span><i>y</i> |
| 173 |
arguments and the <i>x</i><span class="roman"> and </span><i>y</i> arguments to the last |
| 174 |
<b>scan mark</b> command for the widget. |
| 175 |
It then adjusts the view by 10 times the |
| 176 |
difference in coordinates. This command is typically associated |
| 177 |
with mouse motion events in the widget, to produce the effect of |
| 178 |
dragging the list at high speed through the window. The return |
| 179 |
value is an empty string. |
| 180 |
</p></dd> |
| 181 |
</dl> |
| 182 |
</dd> |
| 183 |
<dt><i>pathName </i><b>:select </b><i>option arg</i></dt> |
| 184 |
<dd><p>This command is used to adjust the selection within a listbox. It |
| 185 |
has several forms, depending on <i>option</i>. In all of the forms |
| 186 |
the index <b>end</b> refers to the last element in the listbox. |
| 187 |
</p><dl compact="compact"> |
| 188 |
<dt><i>pathName </i><b>:select :adjust </b><i>index</i></dt> |
| 189 |
<dd><p>Locate the end of the selection nearest to the element given by |
| 190 |
<i>index</i><span class="roman">, and adjust that end of the selection to be at </span><i>index</i> |
| 191 |
(i.e including but not going beyond <i>index</i>). The other |
| 192 |
end of the selection is made the anchor point for future |
| 193 |
<b>select to</b> commands. If the selection |
| 194 |
isn’t currently in the listbox, then this command is identical to |
| 195 |
the <b>select from</b> widget command. |
| 196 |
Returns an empty string. |
| 197 |
</p></dd> |
| 198 |
<dt><i>pathName </i><b>:select :clear</b></dt> |
| 199 |
<dd><p>If the selection is in this listbox then it is cleared so that |
| 200 |
none of the listbox’s elements are selected anymore. |
| 201 |
</p></dd> |
| 202 |
<dt><i>pathName </i><b>:select :from </b><i>index</i></dt> |
| 203 |
<dd><p>Set the selection to consist of element <i>index</i>, and make |
| 204 |
<i>index</i><span class="roman"> the anchor point for future </span><b>select to</b> widget |
| 205 |
commands. Returns an empty string. |
| 206 |
</p></dd> |
| 207 |
<dt><i>pathName </i><b>:select :to </b><i>index</i></dt> |
| 208 |
<dd><p>Set the selection to consist of the elements from the anchor |
| 209 |
point to element <i>index</i>, inclusive. The anchor point is |
| 210 |
determined by the most recent <b>select from</b><span class="roman"> or </span><b>select adjust</b> |
| 211 |
command in this widget. If the selection isn’t in this widget, |
| 212 |
this command is identical to <b>select from</b>. |
| 213 |
Returns an empty string. |
| 214 |
</p></dd> |
| 215 |
</dl> |
| 216 |
|
| 217 |
</dd> |
| 218 |
<dt><i>pathName </i><b>:size</b></dt> |
| 219 |
<dd><p>Returns a decimal string indicating the total number of elements |
| 220 |
in the listbox. |
| 221 |
</p></dd> |
| 222 |
<dt><i>pathName </i><b>:xview </b><i>index</i></dt> |
| 223 |
<dd><p>Adjust the view in the listbox so that character position <i>index</i> |
| 224 |
is displayed at the left edge of the widget. |
| 225 |
Returns an empty string. |
| 226 |
</p></dd> |
| 227 |
<dt><i>pathName </i><b>:yview </b><i>index</i></dt> |
| 228 |
<dd><p>Adjust the view in the listbox so that element <i>index</i> is |
| 229 |
displayed at the top of the widget. |
| 230 |
If <i>index</i><span class="roman"> is specified as </span><b>end</b> it indicates the last |
| 231 |
element of the listbox. Returns an empty string. |
| 232 |
</p> |
| 233 |
</dd> |
| 234 |
</dl> |
| 235 |
<span id="g_t_0022Default-Bindings_0022-1"></span><h4 class="unnumberedsubsec">"Default Bindings"</h4> |
| 236 |
|
| 237 |
<p>Tk automatically creates class bindings for listboxes that give them |
| 238 |
the following default behavior: |
| 239 |
</p><ul class="no-bullet"> |
| 240 |
<li> [1] |
| 241 |
When button 1 is pressed over a listbox, the element underneath the |
| 242 |
mouse cursor is selected. The mouse can be dragged to select a |
| 243 |
range of elements. |
| 244 |
</li><li> [2] |
| 245 |
The ends of the selection can be adjusted by dragging with mouse |
| 246 |
button 1 while the shift key is down; this will adjust the end |
| 247 |
of the selection that was nearest to the mouse cursor when button |
| 248 |
1 was pressed. |
| 249 |
</li><li> [3] |
| 250 |
The view in the listbox can be adjusted by dragging with mouse button 2. |
| 251 |
</li></ul> |
| 252 |
|
| 253 |
<p>The behavior of listboxes can be changed by defining new bindings for |
| 254 |
individual widgets or by redefining the class bindings. |
| 255 |
In addition, the procedure <b>tk_listboxSingleSelect</b> may be |
| 256 |
invoked to change listbox behavior so that only a single element |
| 257 |
may be selected at once. |
| 258 |
</p> |
| 259 |
<span id="Keywords-1"></span><h4 class="unnumberedsubsec">Keywords</h4> |
| 260 |
<p>listbox, widget |
| 261 |
</p><hr> |
| 262 |
<div class="header"> |
| 263 |
<p> |
| 264 |
Next: <a href="scale.html" accesskey="n" rel="next">scale</a>, Previous: <a href="button.html" accesskey="p" rel="prev">button</a>, Up: <a href="Widgets.html" accesskey="u" rel="up">Widgets</a> [<a href="wm.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>]</p> |
| 265 |
</div> |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
</body> |
| 270 |
</html> |