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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
|
<!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>entry (GCL TK Manual)</title>
<meta name="description" content="entry (GCL TK Manual)">
<meta name="keywords" content="entry (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="message.html" rel="next" title="message">
<link href="text.html" rel="prev" title="text">
<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="entry"></span><div class="header">
<p>
Next: <a href="message.html" accesskey="n" rel="next">message</a>, Previous: <a href="text.html" accesskey="p" rel="prev">text</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="entry-1"></span><h3 class="section">2.10 entry</h3>
<p>entry \- Create and manipulate entry widgets
</p><span id="Synopsis-9"></span><h4 class="unnumberedsubsec">Synopsis</h4>
<p><b>entry</b><i> </i><i>pathName </i><span class="roman">?</span><i>options</i>?
</p><span id="Standard-Options-9"></span><h4 class="unnumberedsubsec">Standard Options</h4>
<div class="example">
<pre class="example">background foreground insertWidth selectForeground
borderWidth insertBackground relief textVariable
cursor insertBorderWidth scrollCommand
exportSelection insertOffTime selectBackground
font insertOnTime selectBorderWidth
</pre></div>
<p>See <a href="options.html">options</a>, for more information.
</p><span id="Arguments-for-Entry"></span><h4 class="unnumberedsubsec">Arguments for Entry</h4>
<dl compact="compact">
<dt><code><b>:state</b></code></dt>
<dd><p align="right">Name=<code>"<b>state</b><span class="roman">"</span> Class=<code>"</code><b>State</b>"</code>
</p><br>
<p>Specifies one of two states for the entry: <b>normal</b><span class="roman"> or </span><b>disabled</b>.
If the entry is disabled then the value may not be changed using widget
commands and no insertion cursor will be displayed, even if the input focus is
in the widget.
</p></dd>
</dl>
<dl compact="compact">
<dt><code><b>:width</b></code></dt>
<dd><p align="right">Name=<code>"<b>width</b><span class="roman">"</span> Class=<code>"</code><b>Width</b>"</code>
</p><br>
<p>Specifies an integer value indicating the desired width of the entry window,
in average-size characters of the widget’s font.
</p></dd>
</dl>
<span id="Description-6"></span><h4 class="unnumberedsubsec">Description</h4>
<p>The <b>entry</b> command creates a new window (given by the
<i>pathName</i> argument) and makes it into an entry widget.
Additional options, described above, may be specified on the
command line or in the option database
to configure aspects of the entry such as its colors, font,
and relief. The <b>entry</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>An entry is a widget that displays a one-line text string and
allows that string to be edited using widget commands described below, which
are typically bound to keystrokes and mouse actions.
When first created, an entry’s string is empty.
A portion of the entry may be selected as described below.
If an entry is exporting its selection (see the <b>exportSelection</b>
option), then it will observe the standard X11 protocols for handling the
selection; entry selections are available as type <b>STRING</b>.
Entries also observe the standard Tk rules for dealing with the
input focus. When an entry has the input focus it displays an
<i>insertion cursor</i> to indicate where new characters will be
inserted.
</p>
<p>Entries are capable of displaying strings that are too long to
fit entirely within the widget’s window. In this case, only a
portion of the string will be displayed; commands described below
may be used to change the view in the window. Entries use
the standard <b>scrollCommand</b> mechanism for interacting with
scrollbars (see the description of the <b>scrollCommand</b> option
for details). They also support scanning, as described below.
</p>
<span id="A-Entry-Widget_0027s-Arguments"></span><h4 class="unnumberedsubsec">A Entry Widget’s Arguments</h4>
<p>The <b>entry</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.
</p>
<p>Many of the widget commands for entries take one or more indices as
arguments. An index specifies a particular character in the entry’s
string, in any of the following ways:
</p>
<dl compact="compact">
<dt><i>number</i></dt>
<dd><p>Specifies the character as a numerical index, where 0 corresponds
to the first character in the string.
</p></dd>
<dt><b>end</b></dt>
<dd><p>Indicates the character just after the last one in the entry’s string.
This is equivalent to specifying a numerical index equal to the length
of the entry’s string.
</p></dd>
<dt><b>insert</b></dt>
<dd><p>Indicates the character adjacent to and immediately following the
insertion cursor.
</p></dd>
<dt><b>sel.first</b></dt>
<dd><p>Indicates the first character in the selection. It is an error to
use this form if the selection isn’t in the entry window.
</p></dd>
<dt><b>sel.last</b></dt>
<dd><p>Indicates the last character in the selection. It is an error to
use this form if the selection isn’t in the entry window.
</p></dd>
<dt><b>@</b><i>number</i></dt>
<dd><p>In this form, <i>number</i> is treated as an x-coordinate in the
entry’s window; the character spanning that x-coordinate is used.
For example, “<b>@0</b>” indicates the left-most character in the
window.
</p></dd>
</dl>
<p>Abbreviations may be used for any of the forms above, e.g. “<b>e</b>”
or “<b>sel.f</b>”. In general, out-of-range indices are automatically
rounded to the nearest legal value.
</p>
<p>The following commands are possible for entry 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>entry</b>
command.
</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 entry. <i>First</i><span class="roman"> and </span><i>last</i>
are indices of of the first and last characters in the range to
be deleted. If <i>last</i> isn’t specified it defaults to
<i>first</i>, i.e. a single character is deleted. This command
returns an empty string.
</p></dd>
<dt><i>pathName </i><b>:get</b></dt>
<dd><p>Returns the entry’s string.
</p></dd>
<dt><i>pathName </i><b>:icursor </b><i>index</i></dt>
<dd><p>Arrange for the insertion cursor to be displayed just before the character
given by <i>index</i>. Returns an empty string.
</p></dd>
<dt><i>pathName </i><b>:index</b><i> index</i></dt>
<dd><p>Returns the numerical index corresponding to <i>index</i>.
</p></dd>
<dt><i>pathName </i><b>:insert </b><i>index string</i></dt>
<dd><p>Insert the characters of <i>string</i> just before the character
indicated by <i>index</i>. Returns an empty string.
</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 entries. It has
two forms, depending on <i>option</i>:
</p><dl compact="compact">
<dt><i>pathName </i><b>:scan :mark </b><i>x</i></dt>
<dd><p>Records <i>x</i> and the current view in the entry 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</i></dt>
<dd><p>This command computes the difference between its <i>x</i> argument
and the <i>x</i><span class="roman"> argument to the last </span><b>scan mark</b> command for
the widget. It then adjusts the view left or right by 10 times the
difference in x-coordinates. This command is typically associated
with mouse motion events in the widget, to produce the effect of
dragging the entry 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 an entry. It
has several forms, depending on <i>option</i>:
</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 character 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 entry, then a new selection is created to
include the characters between <i>index</i> and the most recent
selection anchor point, inclusive.
Returns an empty string.
</p></dd>
<dt><i>pathName </i><b>:select :clear</b></dt>
<dd><p>Clear the selection if it is currently in this widget. If the
selection isn’t in this widget then the command has no effect.
Returns an empty string.
</p></dd>
<dt><i>pathName </i><b>:select :from </b><i>index</i></dt>
<dd><p>Set the selection anchor point to just before the character
given by <i>index</i>. Doesn’t change the selection.
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
then a new selection is created using the most recent anchor point
specified for the widget. Returns an empty string.
</p></dd>
</dl>
</dd>
<dt><i>pathName </i><b>:view </b><i>index</i></dt>
<dd><p>Adjust the view in the entry so that element <i>index</i> is
at the left edge of the window. Returns an empty string.
</p>
</dd>
</dl>
<span id="g_t_0022Default-Bindings_0022-3"></span><h4 class="unnumberedsubsec">"Default Bindings"</h4>
<p>Tk automatically creates class bindings for entries that give them
the following default behavior:
</p>
<ul class="no-bullet">
<li> [1]
Clicking mouse button 1 in an entry positions the insertion cursor
just before the character underneath the mouse cursor and sets the
input focus to this widget.
</li><li> [2]
Dragging with mouse button 1 strokes out a selection between
the insertion cursor and the character under the mouse.
</li><li> [3]
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> [4]
The view in the entry can be adjusted by dragging with mouse button 2.
</li><li> [5]
If the input focus is in an entry widget and characters are typed on the
keyboard, the characters are inserted just before the insertion cursor.
</li><li> [6]
Control-h and the Backspace and Delete keys erase the character just
before the insertion cursor.
</li><li> [7]
Control-w erases the word just before the insertion cursor.
</li><li> [8]
Control-u clears the entry to an empty string.
</li><li> [9]
Control-v inserts the current selection just before the insertion cursor.
</li><li> [10]
Control-d deletes the selected characters; an error occurs if the selection
is not in this widget.
</li></ul>
<p>If the entry is disabled using the <b>state</b> option, then the entry’s
view can still be adjusted and text in the entry can still be selected,
but no insertion cursor will be displayed and no text modifications will
take place.
</p>
<p>The behavior of entries can be changed by defining new bindings for
individual widgets or by redefining the class bindings.
</p>
<span id="Keywords-9"></span><h4 class="unnumberedsubsec">Keywords</h4>
<p>entry, widget
</p><hr>
<div class="header">
<p>
Next: <a href="message.html" accesskey="n" rel="next">message</a>, Previous: <a href="text.html" accesskey="p" rel="prev">text</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>
|