You're changing focus and triggering focus events ... you're also popping up popups, popups are annoying :) its better to validate on key without popups, popup at most only once on submit, on all others ring the bell and flash invalid
#!/usr/bin/perl --
use strict;
use warnings;
use Tk;
my $mw = tkinit;
my $name = $mw->Entry( -validatecommand => \&nodigits, -validate => '
+key',)->pack;
$name->focus;
#~ $mw->WidgetDump; use Tk::WidgetDump;
$mw->MainLoop;
sub nodigits {
my( $newstring, $difference, $oldstring, $index, $insertOrDelete )
+ = @_;
my $entry = $Tk::event->W;
if( $newstring =~ m/\d/ ){
$entry->bell;
$entry->configure( -bg => 'red' );
$entry->after( 300, sub { $entry->configure( -bg => 'white' )
+} );
return undef;
} else {
$entry->configure( -bg => 'white' );
return 1;
}
}