home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam    

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.2. Entry Methods

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

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

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

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

Converts a named index into a numeric one:

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

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

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

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

Resets the anchor index to the index specified in the second argument:

Determines if any text is currently selected:

if ($entry->selection('present')) {
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:

Extends the selection from the current anchor position to the specified index:

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:

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:

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:

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:


Library Navigation Links

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