in reply to Re: how to use validatecommand for string checking
in thread how to use validatecommand for string checking
So I based on your code and crafted one to hopefully do what I want. The code is written to the best of my knowledge below. However, it appears that the validatecommand only check ONCE in this case. For example, if I type "gh" it will flag error as expected. But after I delete "gh" and retype "gn" it won't flag error anymore! The print command inside the sub is even not invoked at the 2nd mistake I intended to make! Would you please help if you see if there's something wrong here?
Thanks,#!/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); }
Danny
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: how to use validatecommand for string checking
by zentara (Cardinal) on Aug 27, 2007 at 18:39 UTC |