entry

An entry box is designed to allow the user to enter one line of text

See Also

An entry with a history
Echo-free password entry
entryfield
Entry Field Processing
Entry Validation
Entry box validation for IP address
Overwriting an entry char by char
Integer entry validation with range check
Right-to-left entry widget
[spinbox]
Time entry that never contains invalid data
Validating Credit Card Check Digits
Wcb
widget:entry
Mac style search entry widget
Echo-free password entry
uses [entry]'s -show option to hide the password

Documentation

official reference
entry widgetName ?options...?
widgetName subcommand ...

Example: Programmable Scientific Calculator in Two Lines

Why, it can do asin and log ;-)

pack [entry .e -textvar e -width 50]
bind .e <Return> {catch {expr [string map {/ *1.0/} $e]} res; append e " = $res"} ;# RS

The string map forces floating-point calculation, so people won't be disappointed that 1/2 returns 0 ... See A little calculator for discussion.

And, as CL noted, this thingy is programmable: enter for example

[proc fac x {expr {$x<2? 1: $x*[fac [incr x -1]]}}]

into the entry, disregard warnings; now you can do

[fac 10]

and receive [fac 10] = 3628800.0 as result...

GWM I was slightly dissapointed in having to delete the contents of the entry to change the formula significantly so I decided to insert the result in the window title:

pack [entry .e -textvar e -width 50]
bind .e <Return> {catch {expr [string map {/ *1.0/} $e]} res; wm title . " = $res"} ;# RS/GWM variant

I find that slightly easier to use.

Other Examples

[INSERT normal examples of an entry box here - with explanation on the various entry subcommands.]

Hopefully, people will add new pages demonstrating various techniques for doing entry box validation of some common formats, like phone numbers, etc.

The -validatecommand Option

MG: A useful thing with entry widgets for working with files is to use the -validatecommand option to show if the file exists. For example:

entry  .e -textvariable file -width 50 -validate all -validatecommand {isFile %P .e}
button .b -text "Browse..." -command {set file [tk_getOpenFile]}
pack .e .b
proc isFile {f w} {
    if { [file exists $f] && [file isfile $f] } {
        $w configure -fg black
    } else {
        $w configure -fg red
    }
    return 1;
};# Mike Griffiths

Multi-Line Entry Widgets

Peter Newman 2005-03-17: Multi-line entry widgets are easily created using the [text] widget. See:-

Multiline expanding entry widget
LabelText -A Multi Line Entry Widget
Multi-Line Text Entry Widget - With Entry Widget Like Field To Field Tabbing

Misc

Schnexel: Meanwhile I'm thinking about doing a single line entry widget with the text widget: I want some digits extend beyond the right edge, but without staining the visible field by a cut part of the first invisible digit... (using monospaced font is of not much help, at least it gets the stain at always 1px wide)


AMG: I wish that the [$win insert] and [$win delete] commands were combined into a single [$win replace] command that could be used for inserting, changing, and deleting text. Insert text by replacing an empty range with the new text, delete text by replacing a non-empty range with empty string, and change text by replacing a non-empty range with the new text. This would work the same as [lreplace]. However, lreplace doesn't support appending to a list, but this really ought to be fixed. Also, the notation for inserting would be very weird ([$win replace $pos -1 newstuff], where -1 is less than $pos); this can be worked around by retaining [$win insert] and [$win delete] as wrappers around [$win replace], the only command that actually does anything.

Why would I like this change? Because I'm writing some key validation code for [entry], and it triggers two times for each text replace operation. When the user highlights a range then types something new, text is first deleted then inserted. I'd like for that to be a single replace event. And since pure inserts and deletes can be defined in terms of replacement, it makes sense to unify the whole lot.