1entry(n) Tile Widget Set entry(n)
2
3
4
6 ttk::entry - Editable text field widget
7
9 ttk::entry pathName ?options?
10
12 An entry widget displays a one-line text string and allows that string
13 to be edited by the user. The value of the string may be linked to a
14 Tcl variable with the -textvariable option. Entry widgets support hor‐
15 izontal scrolling with the standard -xscrollcommand option and xview
16 widget command. -class -cursor -style -takefocus -xscrollcom‐
17 mand
18
20 [-exportselection exportSelection] A boolean value specifying whether
21 or not a selection in the widget should be linked to the X selection.
22 If the selection is exported, then selecting in the widget deselects
23 the current X selection, selecting outside the widget deselects any
24 widget selection, and the widget will respond to selection retrieval
25 requests when it has a selection. [-invalidcommand invalidCommand] A
26 script template to evaluate whenever the validateCommand returns 0.
27 See VALIDATION below for more information. [-justify justify] Speci‐
28 fies how the text is aligned within the entry widget. One of left,
29 center, or right. [-show show] If this option is specified, then the
30 true contents of the entry are not displayed in the window. Instead,
31 each character in the entry's value will be displayed as the first
32 character in the value of this option, such as ``*''. This is useful,
33 for example, if the entry is to be used to enter a password. If char‐
34 acters in the entry are selected and copied elsewhere, the information
35 copied will be what is displayed, not the true contents of the entry.
36 [-state state] Compatibility option; see widget(n) for details. Speci‐
37 fies one of three states for the entry, normal, disabled, or readonly.
38 See WIDGET STATES, below. [-textvariable textVariable] Specifies the
39 name of a variable whose value is linked to the entry widget's con‐
40 tents. Whenever the variable changes value, the widget's contents are
41 updated, and vice versa. [-validate validate] Specifies the mode in
42 which validation should operate: none, focus, focusin, focusout, key,
43 or all. Default is none, meaning that validation is disabled. See
44 VALIDATION below. [-validatecommand validateCommand] A script template
45 to evaluate whenever validation is triggered. If set to the empty
46 string (the default), validation is disabled. The script must return a
47 boolean value. See VALIDATION below. [-width width] Specifies an
48 integer value indicating the desired width of the entry window, in
49 average-size characters of the widget's font.
50
52 A portion of the entry may be selected as described below. If an entry
53 is exporting its selection (see the exportSelection option), then it
54 will observe the standard X11 protocols for handling the selection;
55 entry selections are available as type STRING. Entries also observe
56 the standard Tk rules for dealing with the input focus. When an entry
57 has the input focus it displays an insert cursor to indicate where new
58 characters will be inserted.
59
60 Entries are capable of displaying strings that are too long to fit
61 entirely within the widget's window. In this case, only a portion of
62 the string will be displayed; commands described below may be used to
63 change the view in the window. Entries use the standard xScrollCommand
64 mechanism for interacting with scrollbars (see the description of the
65 xScrollCommand option for details).
66
68 Many of the entry widget commands take one or more indices as argu‐
69 ments. An index specifies a particular character in the entry's
70 string, in any of the following ways:
71
72 number Specifies the character as a numerical index, where 0 corre‐
73 sponds to the first character in the string.
74
75 @number
76 In this form, number is treated as an x-coordinate in the
77 entry's window; the character spanning that x-coordinate is
78 used. For example, ``@0'' indicates the left-most character in
79 the window.
80
81 end Indicates the character just after the last one in the entry's
82 string. This is equivalent to specifying a numerical index
83 equal to the length of the entry's string.
84
85 insert Indicates the character adjacent to and immediately following
86 the insert cursor.
87
88 sel.first
89 Indicates the first character in the selection. It is an error
90 to use this form if the selection isn't in the entry window.
91
92 sel.last
93 Indicates the character just after the last one in the selec‐
94 tion. It is an error to use this form if the selection isn't in
95 the entry window.
96
97 Abbreviations may be used for any of the forms above, e.g. ``e'' or
98 ``sel.f''. In general, out-of-range indices are automatically rounded
99 to the nearest legal value.
100
102 The following commands are possible for entry widgets:
103
104 pathName bbox index
105 Returns a list of four numbers describing the bounding box of
106 the character given by index. The first two elements of the
107 list give the x and y coordinates of the upper-left corner of
108 the screen area covered by the character (in pixels relative to
109 the widget) and the last two elements give the width and height
110 of the character, in pixels. The bounding box may refer to a
111 region outside the visible area of the window.
112
113 pathName cget option
114 Returns the current value of the specified option. See wid‐
115 get(n).
116
117 pathName configure ?option? ?value option value ...?
118 Modify or query widget options. See widget(n).
119
120 pathName delete first ?last?
121 Delete one or more elements of the entry. First is the index of
122 the first character to delete, and last is the index of the
123 character just after the last one to delete. If last isn't
124 specified it defaults to first+1, i.e. a single character is
125 deleted. This command returns the empty string.
126
127 pathName get
128 Returns the entry's string.
129
130 pathName icursor index
131 Arrange for the insert cursor to be displayed just before the
132 character given by index. Returns the empty string.
133
134 pathName identify x y
135 Returns the name of the element at position x, y, or the empty
136 string if the coordinates are outside the window.
137
138 pathName index index
139 Returns the numerical index corresponding to index.
140
141 pathName insert index string
142 Insert string just before the character indicated by index.
143 Returns the empty string.
144
145 pathName instate statespec ?script?
146 Test the widget state. See widget(n).
147
148 pathName selection option arg
149 This command is used to adjust the selection within an entry.
150 It has several forms, depending on option:
151
152 pathName selection clear
153 Clear the selection if it is currently in this widget.
154 If the selection isn't in this widget then the command
155 has no effect. Returns the empty string.
156
157 pathName selection present
158 Returns 1 if there is are characters selected in the
159 entry, 0 if nothing is selected.
160
161 pathName selection range start end
162 Sets the selection to include the characters starting
163 with the one indexed by start and ending with the one
164 just before end. If end refers to the same character as
165 start or an earlier one, then the entry's selection is
166 cleared.
167
168 pathName state ?stateSpec?
169 Modify or query the widget state. See widget(n).
170
171 pathName validate
172 Force revalidation, independent of the conditions specified by
173 the -validate option. Returns 0 if validation fails, 1 if it
174 succeeds. Sets or clears the invalid state accordingly.
175
176 pathName xview args
177 This command is used to query and change the horizontal position
178 of the text in the widget's window. It can take any of the fol‐
179 lowing forms:
180
181 pathName xview
182 Returns a list containing two elements. Each element is
183 a real fraction between 0 and 1; together they describe
184 the horizontal span that is visible in the window. For
185 example, if the first element is .2 and the second ele‐
186 ment is .6, 20% of the entry's text is off-screen to the
187 left, the middle 40% is visible in the window, and 40% of
188 the text is off-screen to the right. These are the same
189 values passed to scrollbars via the -xscrollcommand
190 option.
191
192 pathName xview index
193 Adjusts the view in the window so that the character
194 given by index is displayed at the left edge of the win‐
195 dow.
196
197 pathName xview moveto fraction
198 Adjusts the view in the window so that the character
199 fraction of the way through the text appears at the left
200 edge of the window. Fraction must be a fraction between
201 0 and 1.
202
203 pathName xview scroll number what
204 This command shifts the view in the window left or right
205 according to number and what. Number must be an integer.
206 What must be either units or pages. If what is units,
207 the view adjusts left or right by number average-width
208 characters on the display; if it is pages then the view
209 adjusts by number screenfuls. If number is negative then
210 characters farther to the left become visible; if it is
211 positive then characters farther to the right become vis‐
212 ible.
213
215 The -validate, -validatecommand, and -invalidcommand options are used
216 to enable entry widget validation.
217
218 VALIDATION MODES
219 There are two main validation modes: prevalidation, in which the -vali‐
220 datecommand is evaluated prior to each edit and the return value is
221 used to determine whether to accept or reject the change; and revalida‐
222 tion, in which the -validatecommand is evaluated to determine whether
223 the current value is valid.
224
225 The -validate option determines when validation occurs; it may be set
226 to any of the following values:
227
228 none Default. This means validation will only occur when specifi‐
229 cally requested by the validate widget command.
230
231 key The entry will be prevalidated prior to each edit (specifically,
232 whenever the insert or delete widget commands are called). If
233 prevalidation fails, the edit is rejected.
234
235 focus The entry is revalidated when the entry receives or loses focus.
236
237 focusin
238 The entry is revalidated when the entry receives focus.
239
240 focusout
241 The entry is revalidated when the entry loses focus.
242
243 all Validation is performed for all above conditions.
244
245 The -invalidcommand is evaluated whenever the -validatecommand returns
246 a false value.
247
248 The -validatecommand and -invalidcommand may modify the entry widget's
249 value via the widget insert or delete commands, or by setting the
250 linked -textvariable. If either does so during prevalidation, then the
251 edit is rejected regardless of the value returned by the -validatecom‐
252 mand.
253
254 If -validatecommand is empty (the default), validation always succeeds.
255
256 VALIDATION SCRIPT SUBSTITUTIONS
257 It is possible to perform percent substitutions on the -validatecommand
258 and invalidCommand, just as in a bind script. The following substitu‐
259 tions are recognized:
260
261 %d Type of action: 1 for insert prevalidation, 0 for delete preval‐
262 idation, or -1 for revalidation.
263
264 %i Index of character string to be inserted/deleted, if any, other‐
265 wise -1.
266
267 %P In prevalidation, the new value of the entry if the edit is
268 accepted. In revalidation, the current value of the entry.
269
270 %s The current value of entry prior to editing.
271
272 %S The text string being inserted/deleted, if any, {} otherwise.
273
274 %v The current value of the -validate option.
275
276 %V The validation condition that triggered the callback (key,
277 focusin, focusout, or forced).
278
279 %W The name of the entry widget.
280
281 DIFFERENCES FROM TK ENTRY WIDGET VALIDATION
282 · The standard Tk entry widget automatically disables validation
283 (by setting -validate to none) if the -validatecommand or
284 -invalidcommand modifies the entry's value. The Tile entry wid‐
285 get only disables validation if one of the validation scripts
286 raises an error, or if -validatecommand does not return a valid
287 boolean value. (Thus, it is not necessary to reenable valida‐
288 tion after modifying the entry value in a validation script).
289
290 · The standard entry widget invokes validation whenever the linked
291 -textvariable is modified; the Tile entry widget does not.
292
294 The entry widget's default bindings enable the following behavior. In
295 the descriptions below, ``word'' refers to a contiguous group of let‐
296 ters, digits, or ``_'' characters, or any single character other than
297 these.
298
299 · Clicking mouse button 1 positions the insert cursor just before
300 the character underneath the mouse cursor, sets the input focus
301 to this widget, and clears any selection in the widget. Drag‐
302 ging with mouse button 1 down strokes out a selection between
303 the insert cursor and the character under the mouse.
304
305 · Double-clicking with mouse button 1 selects the word under the
306 mouse and positions the insert cursor at the end of the word.
307 Dragging after a double click strokes out a selection consisting
308 of whole words.
309
310 · Triple-clicking with mouse button 1 selects all of the text in
311 the entry and positions the insert cursor at the end of the
312 line.
313
314 · The ends of the selection can be adjusted by dragging with mouse
315 button 1 while the Shift key is down. If the button is double-
316 clicked before dragging then the selection will be adjusted in
317 units of whole words.
318
319 · Clicking mouse button 1 with the Control key down will position
320 the insert cursor in the entry without affecting the selection.
321
322 · If any normal printing characters are typed in an entry, they
323 are inserted at the point of the insert cursor.
324
325 · The view in the entry can be adjusted by dragging with mouse
326 button 2. If mouse button 2 is clicked without moving the
327 mouse, the selection is copied into the entry at the position of
328 the mouse cursor.
329
330 · If the mouse is dragged out of the entry on the left or right
331 sides while button 1 is pressed, the entry will automatically
332 scroll to make more text visible (if there is more text off-
333 screen on the side where the mouse left the window).
334
335 · The Left and Right keys move the insert cursor one character to
336 the left or right; they also clear any selection in the entry.
337 If Left or Right is typed with the Shift key down, then the
338 insertion cursor moves and the selection is extended to include
339 the new character. Control-Left and Control-Right move the
340 insert cursor by words, and Control-Shift-Left and Control-
341 Shift-Right move the insert cursor by words and also extend the
342 selection. Control-b and Control-f behave the same as Left and
343 Right, respectively.
344
345 · The Home key and Control-a move the insert cursor to the begin‐
346 ning of the entry and clear any selection in the entry. Shift-
347 Home moves the insert cursor to the beginning of the entry and
348 extends the selection to that point.
349
350 · The End key and Control-e move the insert cursor to the end of
351 the entry and clear any selection in the entry. Shift-End moves
352 the cursor to the end and extends the selection to that point.
353
354 · Control-/ selects all the text in the entry.
355
356 · Control-\ clears any selection in the entry.
357
358 · The standard Tk <<Cut>>, <<Copy>>, <<Paste>>, and <<Clear>> vir‐
359 tual events operate on the selection in the expected manner.
360
361 · The Delete key deletes the selection, if there is one in the
362 entry. If there is no selection, it deletes the character to
363 the right of the insert cursor.
364
365 · The BackSpace key and Control-h delete the selection, if there
366 is one in the entry. If there is no selection, it deletes the
367 character to the left of the insert cursor.
368
369 · Control-d deletes the character to the right of the insert cur‐
370 sor.
371
372 · Control-k deletes all the characters to the right of the inser‐
373 tion cursor.
374
376 In the disabled state, the entry cannot be edited and the text cannot
377 be selected. In the readonly state, no insert cursor is displayed and
378 the entry cannot be edited (specifically: the insert and delete com‐
379 mands have no effect). The disabled state is the same as readonly, and
380 in addition text cannot be selected.
381
382 Note that changes to the linked -textvariable will still be reflected
383 in the entry, even if it is disabled or readonly.
384
385 Typically, the text is "grayed-out" in the disabled state, and a dif‐
386 ferent background is used in the readonly state.
387
388 The entry widget sets the invalid state if revalidation fails, and
389 clears it whenever validation succeeds.
390
392 entry, widget, text field
393
394
395
396tile 0.4 entry(n)