Version 18 of entry

Updated 2004-02-06 21:57:47

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.


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.


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

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