in reply to Re: Tk::Entry widget with textvariable and validatecommand
in thread Tk::Entry widget with textvariable and validatecommand

Hi Ken

thanks for replying. As my question seemed so general and simple to me, I thought I could go without any code. Of course I read the docu first, but it only says that using textvariable and validatecommand "can be dangerous to mix", which doesn't help much. Anyway, let's try with this code snippet:

use Tk; my $mw = MainWindow->new(); my $textvar = 1; $mw->Entry(-textvariable => \$textvar, -validatecommand => sub { my ($new,$changed,$old,$ix,$type) = @_; 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; }, -validate => 'key')->pack(); MainLoop;

When started, a window with an Entry widget appears, with value 1 displayed. If you first enter e.g. the value 7, it will print the message and change the value to 3 (because 7 & 3 = 3). Any further entries will pass unchanged and no message will be printed anymore.

Therefore I assume, that the validate option was set to 'none'. The docu says, that this happens, when some error occurred (maybe setting the textvar from the validatecommand callback is such an error?).

Does this clarify my problem? Do you have any advice, better than my ugly workaround of using an "after" call

Thanks and kind regards
petro4213