G'day xcli,
Welcome to the Monastery.
And ++ for a most commendable first post: if only we could get more (first posts) like that.
I tested your code. Beyond adding a #!/usr/bin/env perl shebang line, your posted source code was unchanged.
My system: Perl 5.22.0; Tk 804.033; Mac OS X 10.10.3
I do recall that I had major problems with Tk and Perl 5.20 versions. My perlbrew list indicates I have both 5.20.0 and 5.20.2. I don't recall details except that I pretty much gave up on any Tk and Perl 5.20 combination. This could potentially be related to issues you're encountering (but that's very much a guess). Normally, I would just switch to 5.20.2 and test with the same Perl version as you; unfortunately, I'm unable to do that in this instance.
On to my testing:
Using the mouse to change pages, the first four blocks of "output" you show were the same for me (including the blank lines). Then, as soon as I hit Tab (to start your "Tab" + "LeftRight" + "Space" sequence), I got "page2 entry KeyRelease fired" as a continuation of the the fourth block.
Your posted output:
page2 raised Going to fire page2 entryKeyRelease page1 entry KeyRelease fired Any thing happened ? page1 raised
My output:
page2 raised Going to fire page2 entryKeyRelease page1 entry KeyRelease fired Any thing happened ? page2 entry KeyRelease fired
[Aside: I notice that you've indented everything you've posted within <code>...</code> tags. It's good that you've used those tags; however, their main purpose is to allow us to see exactly what you're seeing (i.e. a verbatim copy). While not a major issue here, it could be elsewhere, so please copy and paste code and data without any modifications. Thanks.]
In general, your bindings seem to be working fine. Just running the GUI and typing 123 (without any other mouse or key activity) results in:
page1 raised Going to fire page1 entryKeyRelease Any thing happened ? page1 entry KeyRelease fired page1 entry KeyRelease fired page1 entry KeyRelease fired
Similarly, starting the GUI afresh and just holding down the spacebar gives:
page1 raised Going to fire page1 entryKeyRelease Any thing happened ? page1 entry KeyRelease fired page1 entry KeyRelease fired page1 entry KeyRelease fired page1 entry KeyRelease fired page1 entry KeyRelease fired page1 entry KeyRelease fired
and those lines just repeated until I stopped holding down the spacebar.
I believe the reason why the bindings aren't set, when the pages are first displayed, is because the pages were originally created without those bindings. You subsequently configure the pages ($nb->pageconfigure) and, when the pages are subsequently raised, those bindings are available. You'll basically need to look at the order in which you're doing things. Compare -createcmd and -raisecmd in Tk::NoteBook.
I'd also be wary of creating closures over global variables in your callbacks. I posted information about this two days ago: "Re: Returning a value from a Perl Listbox".
See also Tk::event and Tk::bind.
— Ken
In reply to Re: Fail to generate event for Tk::Entry contained in Tk::NoteBook page
by kcott
in thread Fail to generate event for Tk::Entry contained in Tk::NoteBook page
by xcli
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |