It's quite easy to do ... just use the name of the main window in the call to bind instead of the word 'all'. For example:
#!/usr/bin/perl -w use strict; use warnings; use Tk; # Main program my $poe_main_window = new MainWindow(-title => 'Tk Binding example'); my $bg = "green"; my $psub = sub { new_toplevel($poe_main_window) }; my $text = "New Window ('c')"; my @args = (-bg => $bg, -command => $psub, -text => $text); my $button = $poe_main_window->Button(@args)->pack(); $poe_main_window->bind($poe_main_window, '<c>', sub{ $button->invoke } + ); MainLoop; # Subroutines sub new_toplevel { my ($mw) = @_; my $top = $mw->Toplevel(-title => "New TopLevel"); my $lbl = $top->Label(-bg => 'skyblue', -text => "Text Widget")->p +ack(); my $txt = $top->Text(-height => 16, -width => 120)->pack(); }
It's the line:
$poe_main_window->bind($poe_main_window, '<c>', sub{ $button->invoke } + );
which binds the 'c' character only to the window $poe_main_window, rather than any other Toplevel widgets created from it.
Update: You can get more information on binding with: perldoc Tk::bind.
In reply to Re: a binding handles keys pressed in unwanted windows
by liverpole
in thread a binding handles keys pressed in unwanted windows
by spx2
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |