Version 23 of entry

Updated 2005-03-17 00:41:53

http://purl.org/tcl/home/man/tcl8.4/TkCmd/entry.htm

An entry box is designed to allow the user to enter one line of text for use by the application.


[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.


See also:


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...


One common question is about "Echo-free password entry". Entry has an easy answer: its -show option is useful in precisely this situation.


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]}
 proc isFile {f w} {
  if { [file exists $f] && [file isfile $f] } {
       $w configure -fg black
     } else {
       $w configure -fg red
     }
  return 1;
 };# Mike Griffiths

Peter Newman 17 March 2005: Multi-line entry widgets are easily created with the Tk text widget. See:-


Category Widget - Category Command - Tk syntax help - Arts and Crafts of Tcl-Tk Programming