xcli has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fail to generate event for Tk::Entry contained in Tk::NoteBook page
by kcott (Archbishop) on Dec 14, 2015 at 19:39 UTC | |
by xcli (Initiate) on Dec 15, 2015 at 06:00 UTC |