$f2 -> focus; #### 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 the 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 selectable, ... #### #!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) }); }