Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Callback is being executed twice by Tk::entry widget

by graff (Chancellor)
on Apr 22, 2016 at 04:25 UTC ( #1161177=note: print w/replies, xml ) Need Help??


in reply to Callback is being executed twice by Tk::entry widget

Let's suppose you start the program and click into the upper-left Entry; if you hit the tab key, moving focus out of that Entry - without typing any characters in it, focus moves to the lower-left Entry, and the validation for the upper-left Entry gets called only once.

Hit tab again (without typing anything into the lower-left Entry): focus moves back to the upper-left, and the lower-left validation gets called once. Using just the tab key, you bounce back and forth between the two left-hand Entries, and with each focus change, the validation for the Entry you're leaving gets called just once. (UPDATE: What golux said above about the right-hand Entries being disabled on start-up explains why focus only bounces between the two left-hand Entries.)

Now, when you type something into a left-hand Entry before hitting tab, the tab moves focus to the other left-hand Entry, and validation runs once on the Entry where you just typed something in. Because there's content, your validation script for this widget (which doesn't have focus now) moves the focus to its associated right-hand widget.This step causes a second "focusout" event, but this time it's triggered on the other left-hand widget (the one that actually had focus when the validation function started). (UPDATE: Of course, once there is content in a left-hand Entry, its right-hand Entry becomes active, and this changes how focus moves when using the tab character.)

In effect, the way the OP code is set up, whenever focus leaves a non-empty left-hand widget, validation gets run on both left-hand widgets: the first is triggered by the "focusout" caused at the keyboard for one of them (shifting focus to the other), and then the validation forces a "focusout" on the other.

Is there some compelling reason why two pairs of Entries need to be used in combination this way? If you handled just one password_entry + password_confirmation pair, you wouldn't have this problem.

  • Comment on Re: Callback is being executed twice by Tk::entry widget

Replies are listed 'Best First'.
Re^2: Callback is being executed twice by Tk::entry widget
by perlingRod (Novice) on Apr 22, 2016 at 13:16 UTC

    graff - you have described the way it works perfectly. I should have included it in the original post. You also pinpointed the issue, namely a second focusout was happening when leaving $entryThree, even though it was never seen while running the GUI. Thank you

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1161177]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2021-03-07 12:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (121 votes). Check out past polls.

    Notices?