#!/usr/bin/perl -- use strict; use warnings; use Tk; my $mw = MainWindow->new(); my $textvar = 1; my $e = $mw->Entry( -textvariable => \$textvar, -validate => 'key', ); $e->configure( -validatecommand => [ \&myValidate, $e ], ); $e->pack(); MainLoop; sub _configurevalidate_key { $Tk::widget->configure( -validate, 'key' ); } sub myValidate { my( $entry, $new, $changed, $old, $ix, $type ) = @_; #~ $entry->afterIdle( [ \&_configurevalidate_key, $e ] ); $entry->afterIdle( \&_configurevalidate_key ); return 1 if( !defined( $changed ) ); return 1 if( $new eq "" ) or( $type < 0 ); $textvar = $new & 3; # use only 2 low bits print "masked out entry value\n"; return 1; } __END__