in reply to Entry widget, default value and validatecommand
If you only allow the user to enter a single digit number, then change your code to:
use strict; use Tk; my $page2; my $w=0; my $wtf; my $wentry= 3; my $wcb; $page2 = MainWindow -> new(); $wcb = $page2 ->Checkbutton (-text=> '/W:', -variable=> \$w, -font=>"A +dobe 10")->pack; #$wcb->select(); $wtf = $page2 ->Entry (-textvariable=> \ $wentry, -width=>8, -validate=> 'key', -validatecommand=> sub{$_[0] =~ /^\d{0,1}$/}, -invalidcommand=> sub{$page2->bell} )->pack; MainLoop;
You have to allow blank, otherwise the user cannot clear the entry before entering.
If you allow multi-digit numbers, change the regexp to ^\d*$.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Entry widget, default value and validatecommand
by Real Perl (Beadle) on Aug 01, 2005 at 05:03 UTC | |
by GrandFather (Saint) on Aug 01, 2005 at 05:12 UTC |