in reply to Key bindings for Tk::Frame?
This first script shows the simplicity of the frame, notice no @_ is passed thru
and here is a way around the problem#!/usr/bin/perl use Tk; my $main = new MainWindow; my $f = $main->Frame(-width => 100, -height => 100)->pack; $f->bind('<Key>' => sub {print "Key: @_\n"} ); $f->bind('<Enter>' => sub { print "enter @_\n" } ); $f->bind('<Leave>' => sub { print "leave @_\n" } ); $f->focus; MainLoop;
#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new; my $f = $mw->Frame(-width => 100, -height => 100)->pack; #$mw->bind( '<KeyPress>' => \&print_keysym ); $f->bind( '<KeyPress>' => \&print_keysym ); $mw->Button( -text => 'Exit', -command => sub { exit(); } )->pack; #button gets the default window focus, so we need # to give it to the frame $f->focus; # won't work without this MainLoop; sub print_keysym { my $widget = shift; my $e = $widget->XEvent; my ( $keysym_text, $keysym_decimal ) = ( $e->K, $e->N ); print "keysym=$keysym_text, numberic=$keysym_decimal\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Key bindings for Tk::Frame?
by pdsx (Initiate) on Feb 03, 2010 at 19:09 UTC | |
|
Re^2: Key bindings for Tk::Frame?
by Anonymous Monk on Feb 03, 2010 at 16:57 UTC |