#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); $mw->geometry("200x100+0+0"); $mw->Entry( -text => '',-width => 20)->pack(); $mw->Checkbutton( -text => 'focus on me and press ? or !' )->pack; my $mwbis = $mw->Toplevel(); $mwbis->geometry("200x100+300+0"); $mwbis->Entry( -text => '',-width => 20)->pack(); $mwbis->Checkbutton( -text => 'focus on me and press ? or !' )->pack; # a lookup table for all global bindings my %bind_table = ( '' => sub{print "A question mark was pressed!!\n"}, '' => sub{print "A esclamation mark was pressed!!\n"}, ); foreach my $window ($mw, $mwbis){ # assign bindings to all TopLevel foreach my $bind (keys %bind_table){ $window->bind($bind => $bind_table{$bind}); # remove bindings for all Tk::Entry in all windows $window->bind('Tk::Entry', $bind,sub{Tk->break}); } # bind Return to for Tk::Entry to give the focus to parent $window->bind('Tk::Entry','' => sub{$_[0]->parent->focus}) } MainLoop;