I'm trying to set a validate command allowing for only positive or negative integers. I also want a reset button to clear the entry. This doesn't seem to be working properly. Can anyone offer some advice? Thanks.
#!usr/bin/perl use Tk; use strict; use warnings; # my $value; my $mw=new MainWindow; my $ent = $mw -> Entry(-textvariable=> \$value, -validate=>'key', -validatecommand=>sub { $_[0] =~ /-{0,1}\d+$/ }, -invalidcommand=> \&lam_num_error)->pack(); my $print_button = $mw->Button(-text=>"Print", -command=> \&print, -font=>"ansi 10 bold")->pack(); # my $reset_frm = $mw -> Frame(); $reset_frm->pack(-fill=>'both'); my $reset_button = $reset_frm->Button(-text=>"Reset", -command=> \&do_reset, -font=>"ansi 10 bold")->pack(); MainLoop; sub print { print "$value"; } sub do_reset { $ent->delete(0,'end'); } sub lam_num_error { $mw->messageBox(-message=>"The input must be an integer."); }
In reply to Entry Widget - validatecommand by shortyfw06
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |