Book HomeJava and XSLTSearch this book

21.8. The Entry Widget

Create an Entry widget with the Entry method. An entry widget is a space for the user to enter text. The value that the user has typed into the widget is stored in the variable pointed to by the -textvariable option.

$parent->Entry (options)

The standard configuration options that apply to Entry are: -background, -bg, -borderwidth, -bd, -cursor, -exportselection, -font, -foreground, -fg, -high-lightbackground, -highlightcolor, -highlightthickness, -insertbackground, -in-sertborderwidth, -insertofftime, -insertontime, -insertwidth, -justify, -relief, -selectbackground, -selectborderwidth, -selectforeground, -state, -takefocus, and -xscrollcommand.

Other options are:

-show => x
Defines a character to be displayed in place of actual typed text (for use with passwords).

-textvariable => \$variable
Points to the variable containing text to be displayed in the Entry widget. Button text will change as $variable does.

21.8.1. Text Indexes

In an Entry widget, several indexes are defined to identify positions in the entry text. These are used by the methods that retrieve and manipulate entry text.

n
An integer representing a character position, with 0 as the first character in the string.

insert
The character directly after the insert cursor.

sel.first
The first character in the selection block.

sel.last
The character after the last character in the selection block.

anchor
The anchored position.

end
The position just after the last character in the entry string.

@x
The character containing the specified xcoordinate.

21.8.2. Entry Methods

In addition to configure and cget, the following methods are supported for the Entry widget:

delete
Deletes text from the widget. For example, to delete the selected text:

$entry->delete('sel.first', 'sel.last');
get
Gets the contents of the Entry widget. For example:

$input = $entry->get;
icursor
Places the cursor at the specified index. For example, to move the cursor to the end of the entry string:

$entry->icursor('end');
index
Converts a named index into a numeric one:

$length = $entry->index('end');
insert
Inserts text at the specified index. For example, to append the ".txt" string to the end of the entry string:

$entry -> insert('end', '.txt');
selection
Manipulates the selected block. The first argument can be any of:

adjust
Extends selected text to the index specified in the second argument:

$entry->selection('adjust', 'end');
clear
Clears the selection block:

$entry->selection('clear');
from
Resets the anchor index to the index specified in the second argument:

$entry->selection('from',0);
present
Determines if any text is currently selected:

if ($entry->selection('present')) {
        $entry->delete('sel.first','sel.last');
}
range
Changes 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');
to
Extends the selection from the current anchor position to the specified index:

$entry->selection('to','insert');
xview
Manipulates the text in view. With no arguments, returns a list of two numbers between 0 and 1, defining the portion of the entry text that is currently hidden on the left and right sides, respectively. With arguments, the function of xview changes:

index
If 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);
moveto
Moves 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);
scroll
Scrolls 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');


Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.