# hwtk::entry

Editable text field widget.

## Format

hwtk::entry - pathName ?option value? …

## Description

An entry widget displays a one-line text string and allows that string to be edited by the user. The value of the string may be linked to a Tcl variable with the -textvariable option. Entry widgets support horizontal scrolling with the standard -xscrollcommand option and xview widget command.

## Standard Options

-clientdata
Database name: clientData
Database class: ClientData
Acts as a data storage for a widgets. User can store any data and this will not have any effect on widget property.
-cursor
Database name: cursor
Database class: Cursor
Specifies the mouse cursor to be used for the widget. See Tk_GetCursor and cursors(n) in the Tk reference manual for the legal values. If set to the empty string (the default), the cursor is inherited from the parent widget.
-help
Database name: help
Database class: Text
Specifies the text or help message that displays when the cursor moves over the widget.
-helpcommand
Database name: helpcommand
Database class: Command
Dynamic help which calls an assigned -helpcommand when the user moves the mouse on the widget. The text which is returned by the -helpcommand will be in turn be displayed on the tooltip.
-marker
Database name: marker
Database class: Marker
Specifies the color of the marker decorator. Can be either info, error, or warning. If not specified, hide the marker.
-state
Database name: state
Database class: State
May be set to normal or disabled to control the disabled state bit.
-takefocus
Database name: takeFocus
Database class: TakeFocus
Determines whether the window accepts the focus during keyboard traversal. Either 0, 1, a command prefix (to which the widget path is appended, and which should return 0 or 1), or the empty string. See options(n) in the Tk reference manual for the full description.
-textvariable
Database name: textVariable
Database class: Variable
Specifies the name of a global variable. The value of the variable is a text string to be displayed inside the widget; if the variable value changes then the widget will automatically update itself to reflect the new value. The way in which the string is displayed in the widget depends on the particular widget and may be determined by other options, such as anchor or justify.
-width
Database name: width
Database class: Width
Specifies the width of a widget.
-xscrollcommand
Database name: xScrollCommand
Database class: ScrollCommand
Specifies the prefix for a command used to communicate with horizontal scrollbars. When the view in the widget’s window changes (or whenever anything else occurs that could change the display in a scrollbar, such as a change in the total size of the widget’s contents), the widget will generate a Tcl command by concatenating the scroll command and two numbers. Each of the numbers is a fraction between 0 and 1, which indicates a position in the document. 0 indicates the beginning of the document, 1 indicates the end, .333 indicates a position one third the way through the document, and so on. The first fraction indicates the first information in the document that is visible in the window, and the second fraction indicates the information just after the last portion that is visible. The command is then passed to the Tcl interpreter for execution. Typically the xScrollCommand option consists of the path name of a scrollbar widget followed by

## Widget-Specific Options

-command
Database name: command
Database class: Command
A script to evaluate on <Return>.
-inputtype
Database name: inputtype
Database class: InputType
The type of input allowed in the entry field. Valid input types are integer, unsignedinteger, double, bool, hexadecimal, alphanumeric, numeric, real, and string. Default inputtype is string.
-invalidcommand
Database name: invalidCommand
Database class: InvalidCommand
A script template to evaluate whenever the validate command returns 0. See Validation for more information.
-justify
Database name: justify
Database class: Justify
Specifies how the text is aligned within the entry widget. One of left, center, or right.
-marker
Database name: marker
Database class: Marker
Specifies the color of the marker decorator. Can be either info, error, or warning. If not specified, hide the marker.
-show
Database name: show
Database class: Show
If this option is specified, then the true contents of the entry are not displayed in the window. Instead, each character in the entry’s value will be displayed as the first character in the value of this option, such as “*”. This is useful, for example, if the entry is to be used to enter a password. If characters in the entry are selected and copied elsewhere, the information copied will be what is displayed, not the true contents of the entry.
-validate
Database name: validate
Database class: Validate
Specifies the mode in which validation should operate: none, focus, focusin, focusout, key, or all. Default is none, meaning that validation is disabled. See Validation.
-validatecommand
Database name: validateCommand
Database class: ValidateCommand
A script template to evaluate whenever validation is triggered. If set to the empty string (the default), validation is disabled. The script must return a boolean value. See Validation.

## Widget Command

pathName configure ?option? ?value option value …?
Query or modify the configuration options of the widget. If one or more option-value pairs are specified, then the command modifies the given widget option(s) to have the given value(s); in this case the command returns an empty string. If option is specified with no value, then the command returns a list describing the named option: the elements of the list are the option name, database name, database class, default value, and current value. If no option is specified, returns a list describing all of the available options for pathName.
pathName cget option
Returns the current value of the configuration option given by option.
pathName identify element x y
Returns the name of the element under the point given by x and y, or an empty string if the point does not lie within any element. x and y are pixel coordinates relative to the widget. Some widgets accept other identify subcommands.
pathName instate statespec ?script?
Test the widget’s state. If script is not specified, returns 1 if the widget state matches statespec and 0 otherwise. If script is specified, equivalent to
if{[pathNameinstatestateSpec]}script
pathName bbox index
Returns a list of four numbers describing the bounding box of the character given by index. The first two elements of the list give the x and y coordinates of the upper-left corner of the screen area covered by the character (in pixels relative to the widget) and the last two elements give the width and height of the character, in pixels. The bounding box may refer to a region outside the visible area of the window.
pathName delete first ?last?
Delete one or more elements of the entry. First is the index of the first character to delete, and last is the index of the character just after the last one to delete. If last isn’t specified it defaults to first+1, that is, a single character is deleted. This command returns the empty string.
pathName get
Returns the entry's string.
pathName icursor index
Arrange for the insert cursor to be displayed just before the character given by index. Returns the empty string.
pathName index string
Arrange for the insert cursor to be displayed just before the character given by index. Returns the empty string.
pathName insert index string
Insert string just before the character indicated by index. Returns the empty string.
pathName invoke index
Invokes the action of the combobox selection.
pathName selection option arg
This command is used to adjust the selection within an entry. It has several forms, depending on option:
pathName selection clear
Clear the selection if it is currently in this widget. If the selection isn’t in this widget then the command has no effect. Returns the empty string.
pathName selection present
Returns 1 if there is are characters selected in the entry, 0 if nothing is selected.
pathName selection range start end
Sets the selection to include the characters starting with the one indexed by start and ending with the one just before end. If end refers to the same character as start or an earlier one, then the entry’s selection is cleared.
pathName set str
Sets the entity's value to str.
pathName xview args
This command is used to query and change the horizontal position of the text in the widget’s window. It can take any of the following forms:
pathName xview
Returns a list containing two elements. Each element is a real fraction between 0 and 1; together they describe the horizontal span that is visible in the window. For example, if the first element is .2 and the second element is .6, 20% of the entry’s text is offscreen to the left, the middle 40% is visible in the window, and 40% of the text is offscreen to the right. These are the same values passed to scrollbars via the -xscrollcommand option.
pathName xview index
Adjusts the view in the window so that the character given by index is displayed at the left edge of the window.
pathName xview moveto fraction
Adjusts the view in the window so that the character fraction of the way through the text appears at the left edge of the window. fraction must be a fraction between 0 and 1.
pathName xview scroll number what
This command shifts the view in the window left or right according to number and what. Number must be an integer. What must be either units or pages. If what is units, the view adjusts left or right by number average width characters on the display; if it is pages then the view adjusts by number screenfuls. If number is negative then characters farther to the left become visible; if it is positive then characters farther to the right become visible.

## Example

::hwtk::dialog .d -title "::hwtk::entry"
set f [.d recess]

hwtk::label $f.l1 -text "String" hwtk::entry$f.e1 -help "String entry"

hwtk::label $f.l2 -text "Unsigned integer" hwtk::entry$f.e2 -inputtype unsignedinteger -help "Unsigned integer entry"

hwtk::label $f.l3 -text "Double" hwtk::entry$f.e3 -inputtype double -help "Double entry"

hwtk::label $f.l4 -text "Disabled" hwtk::entry$f.e4 -state disabled -help "Disabled entry"

grid columnconfigure $f 1 -weight 1 for {set i 1} {$i<=4} {incr i} {
grid $f.l$i -row $i -col 0 -sticky w; grid$f.e$i -row$i -col 1 -sticky e -pady 2
}

.d post