in reply to perl/Tk Entry validation
The validateCommand will turn itself off by setting validate to none when an error occurs, for example when the validateCommand or invalidCommand encounters an error in its script while evaluating, or validateCommand does not return a valid boolean value.). An easy workaround is to reset the -validate in the invalidcommand:
#!/usr/bin/perl use warnings; use strict; use Tk; my $embCanvas = MainWindow->new; my $xVConsSflEmbMax0 = 1; my $xVConsSflEmbMax = $xVConsSflEmbMax0; my $emb1Entry = $embCanvas->Entry( -textvariable => \$xVConsSflEmbMax, -width => 3, -validate => 'focusout', -validatecommand => sub { warn "@_\n"; $_[0] =~ /^\d*\.?\d+$/ } +, -invalidcommand => \&invalid, )->pack; my $qb = $embCanvas->Button( -text => 'Quit', -command => sub { exit } )->pack; MainLoop(); sub invalid { $xVConsSflEmbMax = $xVConsSflEmbMax0; $emb1Entry->configure(-validate => 'focusout'); }
|
|---|