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