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 global variable whose  value
48       is  linked  to  the  entry  widget's  contents.   Whenever the variable
49       changes value, the widget's  contents  are  updated,  and  vice  versa.
50       [-validate validate]  Specifies  the  mode  in  which validation should
51       operate: none, focus, focusin, focusout, key, or all.  Default is none,
52       meaning  that  validation  is disabled.  See VALIDATION below.  [-vali‐
53       datecommand validateCommand] A script  template  to  evaluate  whenever
54       validation  is  triggered.   If  set to the empty string (the default),
55       validation is disabled.  The script must return a boolean  value.   See
56       VALIDATION below.  [-width width] Specifies an integer value indicating
57       the desired width of the entry window, in  average-size  characters  of
58       the 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.l”.  In general, out-of-range indices are automatically rounded to
108       the nearest legal value.
109

WIDGET COMMAND

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

VALIDATION

213       The  -validate,  -validatecommand, and -invalidcommand options are used
214       to enable entry widget validation.
215
216   VALIDATION MODES
217       There are two main validation modes: prevalidation, in which the -vali‐
218       datecommand  is  evaluated  prior  to each edit and the return value is
219       used to determine whether to accept or reject the change; and revalida‐
220       tion,  in  which the -validatecommand is evaluated to determine whether
221       the current value is valid.
222
223       The -validate option determines when validation occurs; it may  be  set
224       to any of the following values:
225
226              none   Default.   This  means  validation  will  only occur when
227                     specifically requested by the validate widget command.
228
229              key    The  entry  will  be  prevalidated  prior  to  each  edit
230                     (specifically,  whenever the insert or delete widget com‐
231                     mands are called).  If prevalidation fails, the  edit  is
232                     rejected.
233
234              focus  The entry is revalidated when the entry receives or loses
235                     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
262                     prevalidation, or -1 for revalidation.
263
264              %i     Index of character string to be inserted/deleted, if any,
265                     otherwise -1.
266
267              %P     In  prevalidation, the new value of the entry if the edit
268                     is accepted.  In revalidation, the current value  of  the
269                     entry.
270
271              %s     The current value of entry prior to editing.
272
273              %S     The text string being inserted/deleted, if any, {} other‐
274                     wise.
275
276              %v     The current value of the -validate option.
277
278              %V     The validation  condition  that  triggered  the  callback
279                     (key, focusin, focusout, or forced).
280
281              %W     The name of the entry widget.
282
283   DIFFERENCES FROM TK ENTRY WIDGET VALIDATION
284       The standard Tk entry widget automatically disables validation (by set‐
285       ting -validate to none) if the -validatecommand or -invalidcommand mod‐
286       ifies the entry's value.  The Tk themed entry widget only disables val‐
287       idation if one of the validation scripts raises an error, or if  -vali‐
288       datecommand  does  not  return a valid boolean value.  (Thus, it is not
289       necessary to re-enable validation after modifying the entry value in  a
290       validation script).
291
292       In  addition, the standard entry widget invokes validation whenever the
293       linked -textvariable is modified; the Tk themed entry widget does not.
294

DEFAULT BINDINGS

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

WIDGET STATES

374       In  the  disabled state, the entry cannot be edited and the text cannot
375       be selected.  In the readonly state, no insert cursor is displayed  and
376       the  entry  cannot  be edited (specifically: the insert and delete com‐
377       mands have no effect).  The disabled state is the same as readonly, and
378       in addition text cannot be selected.
379
380       Note  that  changes to the linked -textvariable will still be reflected
381       in the entry, even if it is disabled or readonly.
382
383       Typically, the text is “grayed-out” in the disabled state, and  a  dif‐
384       ferent background is used in the readonly state.
385
386       The  entry  widget  sets  the  invalid state if revalidation fails, and
387       clears it whenever validation succeeds.
388

SEE ALSO

390       ttk::widget(n), entry(n)
391

KEYWORDS

393       entry, widget, text field
394
395
396
397Tk                                    8.5                        ttk::entry(n)
Impressum