#!/usr/bin/env perl use English; require Tk; use Tk; use Tk; my $mw = MainWindow->new(); my $entry = $mw->Entry()->pack(); $entry->configure( -textvariable => \$content , -validate => 'key' , -validatecommand => sub { my $newvalue = shift; my $changedchars = shift; my $currentvalue = shift; my $index = shift; my $type = shift; print "newval-> $newvalue\nchangedchars-> $changedchars\n". "curvalue-> $currentvalue\n index-> $index\n\n\n"; if( ($index == 0) and ($newvalue ne 'g')){return 0} if( ($index == 1) and ($newvalue ne 'go')){return 0} if( ($index == 2) and ($newvalue ne 'go ')){return 0} return 1; }, -invalidcommand => [ \&errorsub , \$entry ] ) ; MainLoop; sub errorsub { print "ERROR.\n"; $content = "" ; $entry->focus; $entry->icursor(0); }