in reply to Re^5: Tk vs Tkx for -validatecommand
in thread Tk vs Tkx for -validatecommand
Thank you Anonymous Monk. I fixed the script but the validatecommand is still not doing what I expect. I want it to give an immediate error if an invalid character is input into the entry.
#! perl use strict; use warnings; use Tkx; my $value; my $mw = Tkx::widget->new("."); my $frame = $mw -> new_frame(); $frame->g_pack(); my $ent = $frame ->new_entry(-textvariable => \$value); $ent->g_pack(); $ent->configure(-validatecommand => [sub { $_[0] =~ /^(?:|-|\d+|-\d+)$ +/ }, Tkx::Ev('%P'), $ent], -invalidcommand => \&lam_num_error); my $print_button = $mw->new_button(-text => "Print", -command => \&printx, -font => "ansi 10 bold")->g_pack(); my $reset_frm = $mw->new_frame(); $reset_frm->g_pack(-fill => 'both'); my $reset_button = $reset_frm->new_button(-text => "Reset", -command => \&do_reset, -font => "ansi 10 bold")->g_p +ack(); Tkx::MainLoop(); sub printx { print $value unless $value eq '-'; } sub do_reset { $ent->delete(0, 'end'); } sub lam_num_error { Tkx::tk___mmessageBox(-message => "The input must be an integer.") +; } __END__
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^7: Tk vs Tkx for -validatecommand
by Anonymous Monk on Sep 20, 2012 at 23:54 UTC | |
by shortyfw06 (Beadle) on Oct 29, 2012 at 13:44 UTC | |
by Anonymous Monk on Oct 30, 2012 at 05:26 UTC |
In Section
Seekers of Perl Wisdom