Create an entry widget with the Entry method. The
value that the user has typed into
the widget is stored in the variable pointed to by the
-textvariable option.
The standard configuration options that apply to$parent->Entry (options)
Entry are:
-background,
-bg,
-borderwidth,
-bd,
-cursor,
-exportselection,
-font,
-foreground,
-fg,
-highlightbackground,
-highlightcolor,
-highlightthickness,
-insertbackground,
-insertborderwidth,
-insertofftime,
-insertontime,
-insertwidth,
-justify,
-relief,
-selectbackground,
-selectborderwidth,
-selectforeground,
-state,
-takefocus,
and
-xscrollcommand.Other options are:
-show => xDefines a character to be displayed in place of actual typed text (for use with passwords).
-textvariable => \$variablePoints to the variable containing text to be displayed in the entry widget.
Button text will change as $variable does.
In an Entry widget, several indexes are defined to identify positions in the entry text, for use by the methods used for retrieving or manipulating entry text. These indexes are:
nAn integer representing a character position, with 0 as the first character in the string.
insertsel.firstsel.lastThe character after the last character in the selection block.
anchorendThe position just after the last character in the entry string.
@xThe character containing the specified x coordinate.
In addition to configure and cget, the following
methods are supported for the Entry widget:
deleteDeletes text from the widget. For example, to delete the selected text:
$entry->delete('sel.first', 'sel.last');
getGets the contents of the entry widget. For example:
$input = $entry->get;
icursorPlaces the cursor at the specified index. For example, to move the cursor to the very end of the entry string:
$entry->icursor('end');
indexConverts a named index into a numeric one.
$length = $entry->index('end');
insertInserts text at the specified index. For example, to append the ".txt" string to the end of the entry string:
$entry -> insert('end', '.txt');
selectionManipulates the selected block. The first argument can be any of:
adjustExtends selected text to the index specified in the second argument.
$entry->selection('adjust', 'end');
clearClears the selection block.
$entry->selection('clear');
fromResets the "anchor" index to the index specified in the second argument.
$entry->selection('from',0);
presentDetermines if any text is currently selected.
if ($entry->selection('present')) {
$entry->delete('sel.first','sel.last');
}
rangeChanges the selection range to the indexes specified in the second and third arguments. For example, to change the selection to include the entire entry string:
$entry->selection('range',0,'end');
toExtends the selection from the current anchor position to the specified index.
$entry->selection('to','insert');
xviewManipulates the text in view. With no arguments, returns a
list of two numbers between 0 and 1, defining what portion of the
entry text is currently hidden on the left and right sides,
respectively. With arguments, the function of xview
changes:
indexIf the first argument is an index, that position becomes the leftmost position in view. For example, to reset the visible portion to the beginning of the string:
$entry->xview(0);
movetoMoves the specified fraction of the entry text to the left of the visible portion. For example, to hide the first 10% of the entry text:
$entry->xview('moveto',0.1);scrollScrolls the text left or right by the specified number of units (characters, in this context) or pages. Used mainly as a callback to a scrollbar; pressing on an arrow moves by units (characters), and pressing on the trough moves by pages. The number is either 1 or -1, to move forwards or backwards, respectively. For example:
$entry->xview('scroll',1,'units');