perlingRod has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to collect multiple passwords using a perl/Tk GUI that is not behaving as I think it should :(
The subroutine "first" gets executed twice upon focusout of the any Tk::entry widget on the left hand side. What am I doing wrong?
#!C:\Windows\Config\UMS_Scripts\perl\bin\perl use strict; use warnings; use Tk; my $globalVar = 0; 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'); $f2 -> focus; # $f2 -> update; } else { } } sub second { my ($f1, $f2) = @_; print "in sub second\n"; $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"; } my $Mw = MainWindow->new(-title=>'Collecting Passwords'); my $entryOne = $Mw -> Entry(-validate=>'focusout') -> grid(-row=>0, -c +olumn=>0); my $entryTwo = $Mw -> Entry(-validate=>'focusout', -state=>'disabled') + -> grid(-row=>0, -column=>1); $entryOne -> configure(-validatecommand=>sub {first($entryOne, $entryT +wo)}); $entryTwo -> configure(-validatecommand=>sub {second($entryOne, $entry +Two)}); my $entryThree = $Mw -> Entry(-validate=>'focusout') -> grid(-row=>1, +-column=>0); my $entryFour = $Mw -> Entry(-validate=>'focusout', -state=>'disabled' +) -> grid(-row=>1, -column=>1); $entryThree -> configure(-validatecommand=>sub {first($entryThree, $en +tryFour)}); $entryFour -> configure(-validatecommand=>sub {second($entryThree, $en +tryFour)}); MainLoop;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Callback is being executed twice by Tk::entry widget
by graff (Chancellor) on Apr 22, 2016 at 04:25 UTC | |
by perlingRod (Novice) on Apr 22, 2016 at 13:16 UTC | |
|
Re: Callback is being executed twice by Tk::entry widget
by golux (Chaplain) on Apr 22, 2016 at 04:04 UTC | |
by perlingRod (Novice) on Apr 22, 2016 at 13:31 UTC | |
|
Re: Callback is being executed twice by Tk::entry widget
by Anonymous Monk on Apr 22, 2016 at 01:23 UTC | |
by perlingRod (Novice) on Apr 22, 2016 at 13:10 UTC |