Hi perlingRod,

You're getting a double callback because of this line in your code:

$f2 -> focus;

Don't do that; it's triggering a focusout event on $f2, causing $f2 to enter its validation callback.

Note too, the first time you validate on $entryOne or $entryThree the corresponding column 2 Entry widget $entryTwo or $entryFour will not have been selectable, so the focus will skip to the other first-column Entry widget. If this isn't what you want, you could change the disabled states to readonly instead, because according to the Entry widget docs:

Switch: -state ... If the entry is readonly, then the value may not be changed using +widget commands and no insertion cursor will be displayed, even if th +e input focus is in the widget; the contents of the widget may still +be selected. If the entry is disabled, the value may not be changed, +no insertion cursor will be displayed, the contents will not be selec +table, ...

Finally, a suggestion (which you are free to take as you will). I find it useful to simplify Tk code by writing subroutines that consolidate common values. Since you're creating 4 Entry widgets with the same validation method, and your validation calls the same 2 subroutine, why not extrapolate that to the 2 new subroutines (here called entry and config_validate):

#!C:\Windows\Config\UMS_Scripts\perl\bin\perl use strict; use warnings; use Tk; my $globalVar = 0; ################# ## Subroutines ## ################# sub first { my ($f1, $f2) = @_; $globalVar = $globalVar + 1; print "in sub first for the $globalVar time\n"; my $count = 1; for my $anArg (@_) { if (defined $anArg) { print "$count - $anArg\n"; } else { print "$count\n"; } $count = $count + 1; } my $value1 = $f1 -> get(); my $length1 = length $value1; print "value1: $value1 :$length1\n"; my $value2 = $f2 -> get(); my $length2 = length $value2; print "value2: $value2 :$length2\n"; if ($length1 > 0) { $f2 -> configure(-state=>'normal'); ## Don't do this -- it invoke the focusout event prematurely # $f2 -> focus; # $f2 -> update; } else { } } sub second { my ($f1, $f2) = @_; print "in sub second\n"; ## You probably don't need this -- unused in this subroutine # $globalVar = $globalVar + 1; my $count = 1; for my $anArg (@_) { if (defined $anArg) { print "$count - $anArg\n"; } else { print "$count\n"; } $count = $count + 1; } my $value1 = $f1 -> get(); my $length1 = length $value1; print "value1: $value1 :$length1\n"; my $value2 = $f2 -> get(); my $length2 = length $value2; print "value2: $value2 :$length2\n"; } ################## ## Main Program ## ################## my $Mw = MainWindow->new(-title=>'Collecting Passwords'); my $entryOne = entry($Mw, 0, 0, "normal"); my $entryTwo = entry($Mw, 0, 1, "disabled"); my $entryThree = entry($Mw, 1, 0, "normal"); my $entryFour = entry($Mw, 1, 1, "disabled"); config_validate($entryOne, $entryTwo); config_validate($entryThree, $entryFour); MainLoop; ##################### ## New Subroutines ## ##################### sub entry { my ($parent, $row, $col, $state) = @_; my $entry = $parent->Entry(-validate => 'focusout'); $entry->grid(-row => $row, -column => $col); $entry->configure(-state => $state); return $entry; } sub config_validate { my ($ent_A, $ent_B) = @_; $ent_A->configure(-validatecommand => sub { first($ent_A, $ent_B) +}); $ent_B->configure(-validatecommand => sub { second($ent_A, $ent_B) + }); }

Again, you're free to take it or leave it, but I find the simplification makes a Tk program a lot easier to read. Plus, you can easily see where to change the 2 occurrences of "disabled" to "readonly", to see the resulting effect.

Good luck!

Update:   Removed some parameters left over from debugging the root cause of the problem.

Update 2:   Link directly to description of State in the Tk docs for the Entry widget.

say  substr+lc crypt(qw $i3 SI$),4,5

In reply to Re: Callback is being executed twice by Tk::entry widget by golux
in thread Callback is being executed twice by Tk::entry widget by perlingRod

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.