diff options
Diffstat (limited to 'library/demos/entry3.tcl')
-rw-r--r-- | library/demos/entry3.tcl | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/library/demos/entry3.tcl b/library/demos/entry3.tcl index 36daf5b..3d76c2e 100644 --- a/library/demos/entry3.tcl +++ b/library/demos/entry3.tcl @@ -1,4 +1,4 @@ -# entry2.tcl -- +# entry3.tcl -- # # This demonstration script creates several entry widgets whose # permitted input is constrained in some way. It also shows off a @@ -8,6 +8,8 @@ if {![info exists widgetDemo]} { error "This script should be run from the \"widget\" demo." } +package require Tk + set w .entry3 catch {destroy $w} toplevel $w @@ -15,11 +17,10 @@ wm title $w "Constrained Entry Demonstration" wm iconname $w "entry3" positionWindow $w - label $w.msg -font $font -wraplength 5i -justify left -text "Four different\ entries are displayed below. You can add characters by pointing,\ clicking and typing, though each is constrained in what it will\ - accept. The first only accepts integers or the empty string\ + accept. The first only accepts 32-bit integers or the empty string\ (checking when focus leaves it) and will flash to indicate any\ problem. The second only accepts strings with fewer than ten\ characters and sounds the bell when an attempt to go over the limit\ @@ -30,11 +31,9 @@ label $w.msg -font $font -wraplength 5i -justify left -text "Four different\ characters (silently ignoring further ones), and displaying them as\ asterisk characters." -frame $w.buttons -button $w.buttons.dismiss -text Dismiss -command "destroy $w" -button $w.buttons.code -text "See Code" -command "showCode $w" -pack $w.buttons.dismiss $w.buttons.code -side left -expand 1 - +## See Code / Dismiss buttons +set btns [addSeeDismiss $w.buttons $w] +pack $btns -side bottom -fill x # focusAndFlash -- # Error handler for entry widgets that forces the focus onto the @@ -63,6 +62,8 @@ proc focusAndFlash {W fg bg {count 9}} { } labelframe $w.l1 -text "Integer Entry" +# Alternatively try using {string is digit} for arbitrary length numbers, +# and not just 32-bit ones. entry $w.l1.e -validate focus -vcmd {string is integer %P} $w.l1.e configure -invalidcommand \ "focusAndFlash %W [$w.l1.e cget -fg] [$w.l1.e cget -bg]" @@ -181,5 +182,4 @@ grid $w.l1 $w.l2 -in $w.mid -padx 3m -pady 1m -sticky ew grid $w.l3 $w.l4 -in $w.mid -padx 3m -pady 1m -sticky ew grid columnconfigure $w.mid {0 1} -uniform 1 pack $w.msg -side top -pack $w.buttons -side bottom -fill x -pady 2m pack $w.mid -fill both -expand 1 |