1ttk::entry(n)                  Tk Themed Widget                  ttk::entry(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       ttk::entry - Editable text field widget
9

SYNOPSIS

11       ttk::entry pathName ?options?
12_________________________________________________________________
13

DESCRIPTION

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

STANDARD OPTIONS

22       -class                -cursor              -style
23       -takefocus            -xscrollcommand
24
25       See the ttk_widget manual entry for details on the standard options.
26

WIDGET-SPECIFIC OPTIONS

28       [-exportselection exportSelection]  A  boolean value specifying whether
29       or not a selection in the widget should be linked to the  X  selection.
30       If  the  selection  is exported, then selecting in the widget deselects
31       the current X selection, selecting outside  the  widget  deselects  any
32       widget  selection,  and  the widget will respond to selection retrieval
33       requests when it has a selection.   [-invalidcommand invalidCommand]  A
34       script  template  to  evaluate  whenever the validateCommand returns 0.
35       See VALIDATION below for more information.   [-justify justify]  Speci‐
36       fies  how  the  text  is aligned within the entry widget.  One of left,
37       center, or right.  [-show show] If this option is specified,  then  the
38       true  contents  of the entry are not displayed in the window.  Instead,
39       each character in the entry's value will  be  displayed  as  the  first
40       character  in  the value of this option, such as “*” or a bullet.  This
41       is useful, for example, if the entry is to be used to enter a password.
42       If  characters  in  the  entry  are  selected and copied elsewhere, the
43       information copied will be what is displayed, not the true contents  of
44       the entry.  [-state state] Compatibility option; see ttk::widget(n) for
45       details.  Specifies one of three states for  the  entry,  normal,  dis‐
46       abled,   or   readonly.    See   WIDGET   STATES,  below.   [-textvari‐
47       able textVariable] Specifies the name of  a  variable  whose  value  is
48       linked  to  the entry widget's contents.  Whenever the variable changes
49       value, the widget's contents are  updated,  and  vice  versa.   [-vali‐
50       date validate]  Specifies  the mode in which validation should operate:
51       none, focus, focusin, focusout, key, or all.  Default is none,  meaning
52       that  validation  is  disabled.   See VALIDATION below.  [-validatecom‐
53       mand validateCommand] A script template to evaluate whenever validation
54       is  triggered.  If set to the empty string (the default), validation is
55       disabled.  The script must return  a  boolean  value.   See  VALIDATION
56       below.   [-width width]  Specifies  an  integer  value  indicating  the
57       desired width of the entry window, in average-size  characters  of  the
58       widget's font.
59

NOTES

61       A portion of the entry may be selected as described below.  If an entry
62       is exporting its selection (see the exportSelection  option),  then  it
63       will  observe  the  standard  X11 protocols for handling the selection;
64       entry selections are available as type STRING.   Entries  also  observe
65       the  standard Tk rules for dealing with the input focus.  When an entry
66       has the input focus it displays an insert cursor to indicate where  new
67       characters will be inserted.
68
69       Entries  are  capable  of  displaying  strings that are too long to fit
70       entirely within the widget's window.  In this case, only a  portion  of
71       the  string will be displayed;  commands described below may be used to
72       change the view in the window.  Entries use the standard xScrollCommand
73       mechanism  for  interacting with scrollbars (see the description of the
74       xScrollCommand option for details).
75

INDICES

77       Many of the entry widget commands take one or  more  indices  as  argu‐
78       ments.   An  index  specifies  a  particular  character  in the entry's
79       string, in any of the following ways:
80
81       number Specifies the character as a numerical  index,  where  0  corre‐
82              sponds to the first character in the string.
83
84       @number
85              In  this  form,  number  is  treated  as  an x-coordinate in the
86              entry's window;  the character  spanning  that  x-coordinate  is
87              used.   For  example,  “@0” indicates the left-most character in
88              the window.
89
90       end    Indicates the character just after the last one in  the  entry's
91              string.   This  is  equivalent  to  specifying a numerical index
92              equal to the length of the entry's string.
93
94       insert Indicates the character adjacent to  and  immediately  following
95              the insert cursor.
96
97       sel.first
98              Indicates  the first character in the selection.  It is an error
99              to use this form if the selection is not in the entry window.
100
101       sel.last
102              Indicates the character just after the last one  in  the  selec‐
103              tion.   It  is an error to use this form if the selection is not
104              in the entry window.
105
106       Abbreviations may be used for any of the  forms  above,  e.g.   “e”  or
107sel.f”.  In general, out-of-range indices are automatically rounded to
108       the nearest legal value.
109

WIDGET COMMAND

111       The following commands are possible for entry widgets:
112
113       pathName bbox index
114              Returns a list of four numbers describing the  bounding  box  of
115              the  character  given  by  index.  The first two elements of the
116              list give the x and y coordinates of the  upper-left  corner  of
117              the  screen area covered by the character (in pixels relative to
118              the widget) and the last two elements give the width and  height
119              of  the  character,  in pixels.  The bounding box may refer to a
120              region outside the visible area of the window.
121
122       pathName cget option
123              Returns  the  current  value  of  the  specified  option.    See
124              ttk::widget(n).
125
126       pathName configure ?option? ?value option value ...?
127              Modify or query widget options.  See ttk::widget(n).
128
129       pathName delete first ?last?
130              Delete one or more elements of the entry.  First is the index of
131              the first character to delete, and last  is  the  index  of  the
132              character  just  after  the  last one to delete.  If last is not
133              specified it defaults to first+1, i.e.  a  single  character  is
134              deleted.  This command returns the empty string.
135
136       pathName get
137              Returns the entry's string.
138
139       pathName icursor index
140              Arrange  for  the  insert cursor to be displayed just before the
141              character given by index.  Returns the empty string.
142
143       pathName identify x y
144              Returns the name of the element at position x, y, or  the  empty
145              string if the coordinates are outside the window.
146
147       pathName index index
148              Returns the numerical index corresponding to index.
149
150       pathName insert index string
151              Insert  string  just  before  the  character indicated by index.
152              Returns the empty string.
153
154       pathName instate statespec ?script?
155              Test the widget state.  See ttk::widget(n).
156
157       pathName selection option arg
158              This command is used to adjust the selection  within  an  entry.
159              It has several forms, depending on option:
160
161              pathName selection clear
162                     Clear  the  selection  if it is currently in this widget.
163                     If the selection is not in this widget then  the  command
164                     has no effect.  Returns the empty string.
165
166              pathName selection present
167                     Returns  1  if  there  is  are characters selected in the
168                     entry, 0 if nothing is selected.
169
170              pathName selection range start end
171                     Sets the selection to  include  the  characters  starting
172                     with  the  one  indexed  by start and ending with the one
173                     just before end.  If end refers to the same character  as
174                     start  or  an  earlier one, then the entry's selection is
175                     cleared.
176
177       pathName state ?stateSpec?
178              Modify or query the widget state.  See ttk::widget(n).
179
180       pathName validate
181              Force revalidation, independent of the conditions  specified  by
182              the  -validate  option.   Returns 0 if validation fails, 1 if it
183              succeeds.  Sets or clears the invalid state accordingly.
184
185       pathName xview args
186              This command is used to query and change the horizontal position
187              of the text in the widget's window.  It can take any of the fol‐
188              lowing forms:
189
190              pathName xview
191                     Returns a list containing two elements.  Each element  is
192                     a  real  fraction between 0 and 1; together they describe
193                     the horizontal span that is visible in the  window.   For
194                     example,  if  the first element is .2 and the second ele‐
195                     ment is .6, 20% of the entry's text is off-screen to  the
196                     left, the middle 40% is visible in the window, and 40% of
197                     the text is off-screen to the right.  These are the  same
198                     values  passed  to  scrollbars  via  the  -xscrollcommand
199                     option.
200
201              pathName xview index
202                     Adjusts the view in the  window  so  that  the  character
203                     given  by index is displayed at the left edge of the win‐
204                     dow.
205
206              pathName xview moveto fraction
207                     Adjusts the view in the  window  so  that  the  character
208                     fraction  of the way through the text appears at the left
209                     edge of the window.  Fraction must be a fraction  between
210                     0 and 1.
211
212              pathName xview scroll number what
213                     This  command shifts the view in the window left or right
214                     according to number and what.  Number must be an integer.
215                     What  must  be  either units or pages.  If what is units,
216                     the view adjusts left or right  by  number  average-width
217                     characters  on the display;  if it is pages then the view
218                     adjusts by number screenfuls.  If number is negative then
219                     characters  farther to the left become visible;  if it is
220                     positive then characters farther to the right become vis‐
221                     ible.
222

VALIDATION

224       The  -validate,  -validatecommand, and -invalidcommand options are used
225       to enable entry widget validation.
226
227   VALIDATION MODES
228       There are two main validation modes: prevalidation, in which the -vali‐
229       datecommand  is  evaluated  prior  to each edit and the return value is
230       used to determine whether to accept or reject the change; and revalida‐
231       tion,  in  which the -validatecommand is evaluated to determine whether
232       the current value is valid.
233
234       The -validate option determines when validation occurs; it may  be  set
235       to any of the following values:
236
237       none   Default.   This  means  validation will only occur when specifi‐
238              cally requested by the validate widget command.
239
240       key    The entry will be prevalidated prior to each edit (specifically,
241              whenever  the  insert or delete widget commands are called).  If
242              prevalidation fails, the edit is rejected.
243
244       focus  The entry is revalidated when the entry receives or loses focus.
245
246       focusin
247              The entry is revalidated when the entry receives focus.
248
249       focusout
250              The entry is revalidated when the entry loses focus.
251
252       all    Validation is performed for all above conditions.
253
254       The -invalidcommand is evaluated whenever the -validatecommand  returns
255       a false value.
256
257       The  -validatecommand and -invalidcommand may modify the entry widget's
258       value via the widget insert or  delete  commands,  or  by  setting  the
259       linked -textvariable.  If either does so during prevalidation, then the
260       edit is rejected regardless of the value returned by the  -validatecom‐
261       mand.
262
263       If -validatecommand is empty (the default), validation always succeeds.
264
265   VALIDATION SCRIPT SUBSTITUTIONS
266       It is possible to perform percent substitutions on the -validatecommand
267       and invalidCommand, just as in a bind script.  The following  substitu‐
268       tions are recognized:
269
270       %d     Type of action: 1 for insert prevalidation, 0 for delete preval‐
271              idation, or -1 for revalidation.
272
273       %i     Index of character string to be inserted/deleted, if any, other‐
274              wise -1.
275
276       %P     In  prevalidation,  the  new  value  of the entry if the edit is
277              accepted.  In revalidation, the current value of the entry.
278
279       %s     The current value of entry prior to editing.
280
281       %S     The text string being inserted/deleted, if any, {} otherwise.
282
283       %v     The current value of the -validate option.
284
285       %V     The validation  condition  that  triggered  the  callback  (key,
286              focusin, focusout, or forced).
287
288       %W     The name of the entry widget.
289
290   DIFFERENCES FROM TK ENTRY WIDGET VALIDATION
291       ·      The  standard  Tk entry widget automatically disables validation
292              (by setting  -validate  to  none)  if  the  -validatecommand  or
293              -invalidcommand modifies the entry's value.  The Tk themed entry
294              widget only disables validation if one of the validation scripts
295              raises  an error, or if -validatecommand does not return a valid
296              boolean value.  (Thus, it is not necessary to  reenable  valida‐
297              tion after modifying the entry value in a validation script).
298
299       ·      The standard entry widget invokes validation whenever the linked
300              -textvariable is modified; the Tk themed entry widget does not.
301

DEFAULT BINDINGS

303       The entry widget's default bindings enable the following behavior.   In
304       the descriptions below, “word” refers to a contiguous group of letters,
305       digits, or “_” characters, or any single character other than these.
306
307       ·      Clicking mouse button 1 positions the insert cursor just  before
308              the  character underneath the mouse cursor, sets the input focus
309              to this widget, and clears any selection in the  widget.   Drag‐
310              ging  with  mouse  button 1 down strokes out a selection between
311              the insert cursor and the character under the mouse.
312
313       ·      Double-clicking with mouse button 1 selects the word  under  the
314              mouse  and  positions  the insert cursor at the end of the word.
315              Dragging after a double click strokes out a selection consisting
316              of whole words.
317
318       ·      Triple-clicking  with  mouse button 1 selects all of the text in
319              the entry and positions the insert cursor  at  the  end  of  the
320              line.
321
322       ·      The ends of the selection can be adjusted by dragging with mouse
323              button 1 while the Shift key is down.  If the button is  double-
324              clicked  before  dragging then the selection will be adjusted in
325              units of whole words.
326
327       ·      Clicking mouse button 1 with the Control key down will  position
328              the insert cursor in the entry without affecting the selection.
329
330       ·      If  any  normal  printing characters are typed in an entry, they
331              are inserted at the point of the insert cursor.
332
333       ·      The view in the entry can be adjusted  by  dragging  with  mouse
334              button  2.   If  mouse  button  2  is clicked without moving the
335              mouse, the selection is copied into the entry at the position of
336              the mouse cursor.
337
338       ·      If  the  mouse  is dragged out of the entry on the left or right
339              sides while button 1 is pressed, the  entry  will  automatically
340              scroll  to  make  more  text visible (if there is more text off-
341              screen on the side where the mouse left the window).
342
343       ·      The Left and Right keys move the insert cursor one character  to
344              the  left or right;  they also clear any selection in the entry.
345              If Left or Right is typed with the  Shift  key  down,  then  the
346              insertion  cursor moves and the selection is extended to include
347              the new character.   Control-Left  and  Control-Right  move  the
348              insert  cursor  by  words,  and  Control-Shift-Left and Control-
349              Shift-Right move the insert cursor by words and also extend  the
350              selection.   Control-b and Control-f behave the same as Left and
351              Right, respectively.
352
353       ·      The Home key and Control-a move the insert cursor to the  begin‐
354              ning  of the entry and clear any selection in the entry.  Shift-
355              Home moves the insert cursor to the beginning of the  entry  and
356              extends the selection to that point.
357
358       ·      The  End  key and Control-e move the insert cursor to the end of
359              the entry and clear any selection in the entry.  Shift-End moves
360              the cursor to the end and extends the selection to that point.
361
362       ·      Control-/ selects all the text in the entry.
363
364       ·      Control-\ clears any selection in the entry.
365
366       ·      The standard Tk <<Cut>>, <<Copy>>, <<Paste>>, and <<Clear>> vir‐
367              tual events operate on the selection in the expected manner.
368
369       ·      The Delete key deletes the selection, if there  is  one  in  the
370              entry.   If  there  is no selection, it deletes the character to
371              the right of the insert cursor.
372
373       ·      The BackSpace key and Control-h delete the selection,  if  there
374              is  one  in the entry.  If there is no selection, it deletes the
375              character to the left of the insert cursor.
376
377       ·      Control-d deletes the character to the right of the insert  cur‐
378              sor.
379
380       ·      Control-k  deletes all the characters to the right of the inser‐
381              tion cursor.
382

WIDGET STATES

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

SEE ALSO

400       ttk::widget(n), entry(n)
401

KEYWORDS

403       entry, widget, text field
404
405
406
407Tk                                    8.5                        ttk::entry(n)
Impressum