<< Prev | - Up - | Next >> |
An entry widget lets the user enter a single line of text into the widget. An example is shown in Figure 5.8. The initialization message for the entry widget specifies the width of the entry in characters. The same holds true for the width of label widgets displaying text: a value for the width without an unit appended is taken as width in characters and not in pixels.
L={New Tk.label tkInit(parent:W text:'File name:')}
E={New Tk.entry tkInit(parent:W width:20)}
{Tk.batch [pack(L E side:left pady:1#m padx:1#m)
focus(E)]}
focus
To be able to enter text into an entry, the entry needs to have the focus. If a widget has the focus, all input from the keyboard is directed to that widget. A widget that has the focus is drawn with a frame around it. To give the focus to widget, we can use the focus
command as in the above example.
An entry widget can be given the focus also by clicking it with the mouse button. It is also possible to give the focus to button widgets. That allows to invoke actions with keys, and to move the focus between several widgets by pressing keys. For more on this, see focus.
returning entered text
To query the string entered in a widget the command get
is provided. To display the entered string in the Browser we can execute
{Browse {E tkReturnAtom(get $)}}
The string entered in an entry can be deleted, additional characters can be inserted, and so on. More on entry widgets you can find in entry.
<< Prev | - Up - | Next >> |