shortyfw06 has asked for the wisdom of the Perl Monks concerning the following question:
For an entry widget in Tk, I used the following validate command to only allow negative and positive integers. This would give an immediate error if a letter or other character was entered. In Tkx, I do not get an error when the entry is invalid. Is there a different way to do this in Tkx?
#! perl use strict; use warnings; use Tk; my $value; my $mw = new MainWindow; my $ent = $mw->Entry(-textvariable => \$value, -validate => 'key', -validatecommand => sub { $_[0] =~ /^(?:|-|\d+|-\ +d+)$/ }, -invalidcommand => \&lam_num_error)->pack(); my $print_button = $mw->Button(-text => "Print", -command => \&printx, -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")->pac +k(); MainLoop; sub printx { print $value unless $value eq '-'; } sub do_reset { $ent->delete(0, 'end'); } sub lam_num_error { $mw->messageBox(-message => "The input must be an integer."); } __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tk vs Tkx for -validatecommand
by zentara (Cardinal) on Sep 19, 2012 at 15:18 UTC | |
by shortyfw06 (Beadle) on Sep 19, 2012 at 17:32 UTC | |
by Anonymous Monk on Sep 19, 2012 at 18:42 UTC | |
by shortyfw06 (Beadle) on Sep 19, 2012 at 19:40 UTC | |
by Anonymous Monk on Sep 19, 2012 at 20:00 UTC | |
|