Hello Ken,

Thank you very much for your time and kind help !

My output: page2 raised Going to fire page2 entryKeyRelease page1 entry KeyRelease fired Any thing happened ? page2 entry KeyRelease fired

In your output, even though there is a strange "page1 entry KeyRelease fired", "page2 entry KeyRelease fired" matches "Going to fire page2 entryKeyRelease". However, I still could not fire the correct KeyRelease event, after uninstalling ActivePerl 5.20.2.2002 and installing ActivePerl 5.22.0.2200. Specifically, when page1 is raised, the KeyPress event is unexpectedly fired for the entry in page2.

The code modified: (1) add -createcmd (2) change argument types

use strict; use warnings; use Tk; use Tk::NoteBook; # Main Entry my $top = MainWindow->new(); $top->title("Test"); my $nb = $top->NoteBook()->pack(-expand => 1, -fill => 'both'); InitializeNoteBookPage(\$nb, \$nb->add('page1', -label => 'Page 1'), " +Label for Page 1"); InitializeNoteBookPage(\$nb, \$nb->add('page2', -label => 'Page 2'), " +Label for Page 2"); Tk::MainLoop(); # Subroutines start here sub InitializeNoteBookPage{ my($nb, $nbpage, $label_description) = @_; # Widget Initialization my($_label_1) = $$nbpage->Label( -text => $label_description, ); my($_entry_1) = $$nbpage->Entry( -width => 0, ); # Geometry Management $_label_1->grid( -in => $$nbpage, -column => 1, -row => 1, -column +span => 1, -ipadx => 0, -ipady => 0, -padx => 0, -pady => 0, -rowspan + => 1, -sticky => "" ); $_entry_1->grid( -in => $$nbpage, -column => 2, -row => 1, -column +span => 1, -ipadx => 0, -ipady => 0, -padx => 0, -pady => 0, -rowspan + => 1, -sticky => "ew" ); # Resize Behavior $$nbpage->gridRowconfigure (1, -weight => 0, -minsize => 50, -p +ad => 0); $$nbpage->gridColumnconfigure(1, -weight => 0, -minsize => 400, -p +ad => 0); $$nbpage->gridColumnconfigure(2, -weight => 0, -minsize => 400, -p +ad => 0); # Event callbacks $_entry_1->bind("<KeyRelease>", sub { print $$nbpage->name()." ".$_entry_1->name()." KeyRelease fire +d\n"; } ); $$nb->pageconfigure($$nbpage->name(), -createcmd => sub { print "\n".$$nbpage->name()." created \n"; } ); $$nb->pageconfigure($$nbpage->name(), -raisecmd => sub { print "\n".$$nbpage->name()." raised \n"; print "Going to fire ".$$nbpage->name()." ".$_entry_1->name(). +"KeyRelease\n"; $_entry_1->focus(); # If this line is commented out, no <KeyRe +lease> event will be fired at all ?! $_entry_1->eventGenerate("<KeyRelease>"); print "Any thing happened ?\n"; } ); }

The output

D:\Test>perl -v This is perl 5, version 22, subversion 0 (v5.22.0) built for MSWin32-x +86-multi-thread-64int (with 1 registered patch, see perl -V for more detail) Copyright 1987-2015, Larry Wall Binary build 2200 [299195] provided by ActiveState http://www.ActiveSt +ate.com Built Jul 20 2015 18:55:28 Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. D:\Test>perl test2.pl page1 created page1 raised Going to fire page1 entryKeyRelease Any thing happened ? page2 created page2 raised Going to fire page2 entryKeyRelease Any thing happened ? page1 raised Going to fire page1 entryKeyRelease page2 entry KeyRelease fired Any thing happened ? page2 raised Going to fire page2 entryKeyRelease page1 entry KeyRelease fired Any thing happened ? page1 raised Going to fire page1 entryKeyRelease page2 entry KeyRelease fired Any thing happened ?

Your helpful comments below makes sense.

I believe the reason why the bindings aren't set, when the pages are f +irst displayed, is because the pages were originally created without +those bindings. You subsequently configure the pages ($nb->pageconfig +ure) and, when the pages are subsequently raised, those bindings are +available. Compare -createcmd and -raisecmd in Tk::NoteBook.


In reply to Re^2: Fail to generate event for Tk::Entry contained in Tk::NoteBook page by xcli
in thread Fail to generate event for Tk::Entry contained in Tk::NoteBook page by xcli

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.