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       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

NOTES

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

INDICES

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
153sel.l”.  In general, out-of-range indices are automatically rounded to
154       the nearest legal value.
155

WIDGET COMMAND

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       pathName xview args
216              This command is used to query and change the horizontal position
217              of the text in the widget's window.  It can take any of the fol‐
218              lowing forms:
219
220              pathName xview
221                     Returns  a list containing two elements.  Each element is
222                     a real fraction between 0 and 1; together  they  describe
223                     the  horizontal  span that is visible in the window.  For
224                     example, if the first element is .2 and the  second  ele‐
225                     ment  is .6, 20% of the entry's text is off-screen to the
226                     left, the middle 40% is visible in the window, and 40% of
227                     the  text is off-screen to the right.  These are the same
228                     values  passed  to  scrollbars  via  the  -xscrollcommand
229                     option.
230
231              pathName xview index
232                     Adjusts  the  view  in  the  window so that the character
233                     given by index is displayed at the left edge of the  win‐
234                     dow.
235
236              pathName xview moveto fraction
237                     Adjusts  the  view  in  the  window so that the character
238                     fraction of the way through the text appears at the  left
239                     edge  of the window.  Fraction must be a fraction between
240                     0 and 1.
241
242              pathName xview scroll number what
243                     This command shifts the view in the window left or  right
244                     according to number and what.  Number must be an integer.
245                     What must be either units or pages.  If  what  is  units,
246                     the  view  adjusts  left or right by number average-width
247                     characters on the display;  if it is pages then the  view
248                     adjusts by number screenfuls.  If number is negative then
249                     characters farther to the left become visible;  if it  is
250                     positive then characters farther to the right become vis‐
251                     ible.
252
253       The entry widget also supports the following generic ttk::widget widget
254       subcommands (see ttk::widget(n) for details):
255
256              cget                  configure            identify
257              instate               state
258
259

VALIDATION

261       The  -validate,  -validatecommand, and -invalidcommand options are used
262       to enable entry widget validation.
263
264   VALIDATION MODES
265       There are two main validation modes: prevalidation, in which the -vali‐
266       datecommand  is  evaluated  prior  to each edit and the return value is
267       used to determine whether to accept or reject the change; and revalida‐
268       tion,  in  which the -validatecommand is evaluated to determine whether
269       the current value is valid.
270
271       The -validate option determines when validation occurs; it may  be  set
272       to any of the following values:
273
274              none   Default.   This  means  validation  will  only occur when
275                     specifically requested by the validate widget command.
276
277              key    The  entry  will  be  prevalidated  prior  to  each  edit
278                     (specifically,  whenever the insert or delete widget com‐
279                     mands are called).  If prevalidation fails, the  edit  is
280                     rejected.
281
282              focus  The entry is revalidated when the entry receives or loses
283                     focus.
284
285              focusin
286                     The entry is revalidated when the entry receives focus.
287
288              focusout
289                     The entry is revalidated when the entry loses focus.
290
291              all    Validation is performed for all above conditions.
292
293       The -invalidcommand is evaluated whenever the -validatecommand  returns
294       a false value.
295
296       The  -validatecommand and -invalidcommand may modify the entry widget's
297       value via the widget insert or  delete  commands,  or  by  setting  the
298       linked -textvariable.  If either does so during prevalidation, then the
299       edit is rejected regardless of the value returned by the  -validatecom‐
300       mand.
301
302       If -validatecommand is empty (the default), validation always succeeds.
303
304   VALIDATION SCRIPT SUBSTITUTIONS
305       It is possible to perform percent substitutions on the -validatecommand
306       and -invalidcommand, just as in a bind script.  The following substitu‐
307       tions are recognized:
308
309              %d     Type  of action: 1 for insert prevalidation, 0 for delete
310                     prevalidation, or -1 for revalidation.
311
312              %i     Index of character string to be inserted/deleted, if any,
313                     otherwise -1.
314
315              %P     In  prevalidation, the new value of the entry if the edit
316                     is accepted.  In revalidation, the current value  of  the
317                     entry.
318
319              %s     The current value of entry prior to editing.
320
321              %S     The text string being inserted/deleted, if any, {} other‐
322                     wise.
323
324              %v     The current value of the -validate option.
325
326              %V     The validation  condition  that  triggered  the  callback
327                     (key, focusin, focusout, or forced).
328
329              %W     The name of the entry widget.
330
331   DIFFERENCES FROM TK ENTRY WIDGET VALIDATION
332       The standard Tk entry widget automatically disables validation (by set‐
333       ting -validate to none) if the -validatecommand or -invalidcommand mod‐
334       ifies the entry's value.  The Tk themed entry widget only disables val‐
335       idation if one of the validation scripts raises an error, or if  -vali‐
336       datecommand  does  not  return a valid boolean value.  (Thus, it is not
337       necessary to re-enable validation after modifying the entry value in  a
338       validation script).
339
340       In  addition, the standard entry widget invokes validation whenever the
341       linked -textvariable is modified; the Tk themed entry widget does not.
342

DEFAULT BINDINGS

344       The entry widget's default bindings enable the following behavior.   In
345       the descriptions below, “word” refers to a contiguous group of letters,
346       digits, or “_” characters, or any single character other than these.
347
348        ·  Clicking mouse button 1 positions the insert cursor just before the
349           character underneath the mouse cursor, sets the input focus to this
350           widget, and clears any selection  in  the  widget.   Dragging  with
351           mouse button 1 down strokes out a selection between the insert cur‐
352           sor and the character under the mouse.
353
354        ·  Double-clicking with mouse button 1  selects  the  word  under  the
355           mouse  and  positions  the  insert  cursor  at the end of the word.
356           Dragging after a double click strokes out a selection consisting of
357           whole words.
358
359        ·  Triple-clicking  with mouse button 1 selects all of the text in the
360           entry and positions the insert cursor at the end of the line.
361
362        ·  The ends of the selection can be adjusted by  dragging  with  mouse
363           button  1  while  the  Shift key is down.  If the button is double-
364           clicked before dragging then the  selection  will  be  adjusted  in
365           units of whole words.
366
367        ·  Clicking mouse button 1 with the Control key down will position the
368           insert cursor in the entry without affecting the selection.
369
370        ·  If any normal printing characters are typed in an entry,  they  are
371           inserted at the point of the insert cursor.
372
373        ·  The view in the entry can be adjusted by dragging with mouse button
374           2.  If mouse button 2 is clicked  without  moving  the  mouse,  the
375           selection  is  copied  into  the entry at the position of the mouse
376           cursor.
377
378        ·  If the mouse is dragged out of the entry on the left or right sides
379           while  button  1 is pressed, the entry will automatically scroll to
380           make more text visible (if there is more  text  off-screen  on  the
381           side where the mouse left the window).
382
383        ·  The Left and Right keys move the insert cursor one character to the
384           left or right;  they also clear any selection  in  the  entry.   If
385           Left  or Right is typed with the Shift key down, then the insertion
386           cursor moves and the selection is extended to include the new char‐
387           acter.   Control-Left  and  Control-Right move the insert cursor by
388           words, and  Control-Shift-Left  and  Control-Shift-Right  move  the
389           insert  cursor  by  words and also extend the selection.  Control-b
390           and Control-f behave the same as Left and Right, respectively.
391
392        ·  The Home key and Control-a move the insert cursor to the  beginning
393           of  the  entry  and  clear  any selection in the entry.  Shift-Home
394           moves the insert cursor to the beginning of the entry  and  extends
395           the selection to that point.
396
397        ·  The  End key and Control-e move the insert cursor to the end of the
398           entry and clear any selection in the entry.   Shift-End  moves  the
399           cursor to the end and extends the selection to that point.
400
401        ·  Control-/ selects all the text in the entry.
402
403        ·  Control-\ clears any selection in the entry.
404
405        ·  The standard Tk <<Cut>>, <<Copy>>, <<Paste>>, and <<Clear>> virtual
406           events operate on the selection in the expected manner.
407
408        ·  The Delete key deletes the selection, if there is one in the entry.
409           If  there is no selection, it deletes the character to the right of
410           the insert cursor.
411
412        ·  The BackSpace key and Control-h delete the selection, if  there  is
413           one in the entry.  If there is no selection, it deletes the charac‐
414           ter to the left of the insert cursor.
415
416        ·  Control-d deletes the character to the right of the insert cursor.
417
418        ·  Control-k deletes all the characters to the right of the  insertion
419           cursor.
420

WIDGET STATES

422       In  the  disabled state, the entry cannot be edited and the text cannot
423       be selected.  In the readonly state, no insert cursor is displayed  and
424       the  entry  cannot  be edited (specifically: the insert and delete com‐
425       mands have no effect).  The disabled state is the same as readonly, and
426       in addition text cannot be selected.
427
428       Note  that  changes to the linked -textvariable will still be reflected
429       in the entry, even if it is disabled or readonly.
430
431       Typically, the text is “grayed-out” in the disabled state, and  a  dif‐
432       ferent background is used in the readonly state.
433
434       The  entry  widget  sets  the  invalid state if revalidation fails, and
435       clears it whenever validation succeeds.
436

SEE ALSO

438       ttk::widget(n), entry(n)
439

KEYWORDS

441       entry, widget, text field
442
443
444
445Tk                                    8.5                        ttk::entry(n)
Impressum