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