The code below initializes a two-page Tk::NoteBook, each page of which contains a Tk::Entry. It tries to generate <KeyRelease> event for Tk::Entry when its parent Tk::NoteBook page is raised, but fails.

Specifically, it seems strange that :

1. the Tk::Entry's KeyRelease event handler will **not** be called at the first **two** page raise event triggered by mouse click;

2. starting from the third page raise event triggered by mouse click, **wrong** Tk::Entry's KeyRelease event handler will be called;

3. if Tk::Entry->focus is commented out in the page raise event handler, no <KeyRelease> event will be fired for Tk::Entry at all.

Could you comment about the reason of the error and suggest how to correctly trigger the Tk::Entry KeyRelease event in its container page's raise event ?

PS: Tk 804.033 & ActiveState Perl 5.20.2.2002 & Windows 10 10240 X64

The code:

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->add('page1', -label => 'Page 1'), "Lab +el for Page 1"); InitializeNoteBookPage($nb->add('page2', -label => 'Page 2'), "Lab +el for Page 2"); Tk::MainLoop(); # Subroutines start here sub InitializeNoteBookPage{ my($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, -col +umnspan => 1, -ipadx => 0, -ipady => 0, -padx => 0, -pady => 0, -rows +pan => 1, -sticky => "" ); $_entry_1->grid( -in => $nbpage, -column => 2, -row => 1, -col +umnspan => 1, -ipadx => 0, -ipady => 0, -padx => 0, -pady => 0, -rows +pan => 1, -sticky => "ew" ); # Resize Behavior $nbpage->gridRowconfigure (1, -weight => 0, -minsize => 50, + -pad => 0); $nbpage->gridColumnconfigure(1, -weight => 0, -minsize => 400, + -pad => 0); $nbpage->gridColumnconfigure(2, -weight => 0, -minsize => 400, + -pad => 0); # Event callbacks $_entry_1->bind("<KeyRelease>", sub { print $nbpage->name()." ".$_entry_1->name()." KeyRelease f +ired\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 <K +eyRelease> event will be fired at all ?! $_entry_1->eventGenerate("<KeyRelease>"); print "Any thing happened ?\n"; } ); }

The output:

page1 raised Going to fire page1 entryKeyRelease Any thing happened ? 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 <--- using "Tab" + "LeftRight" + + "Space" Going to fire page1 entryKeyRelease Any thing happened ? page1 entry KeyRelease fired


In reply to 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.