Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Running Perl/Tk under Windows/XP. Tried to bind a key to a subroutine call with an argument, but it didn't work. Here is stripped-down code:
When I press the button, I get this (as expected):use Tk; sub print_args { $ix = 0; foreach $arg (@_) { print "ARG $ix = $arg \n"; $ix++; } print "------------------\n"; } $mw = MainWindow -> new (); $mw -> title ("Test bind with parms"); $fill = $mw -> Label (-text => "TEST BIND - try both button and dow +n arrow") -> pack (); $quit_but = $mw -> Button (-text => "QUIT", -background => "#ffffcc", -borderwidth => 5, -relief => ridge, -command => sub{exit}) -> pack (-side => bottom, -fill => "x"); $test_but = $mw -> Button (-text => "Invoke via button", -background => "#ddffff", -borderwidth => 5, -relief => ridge, -command => [ \&print_args, 3, 2, 11 ] ) -> pack (-side => bottom, -fill => "x"); $mw -> bind ('<Key-Down>' => [ \&print_args, 3, 2, 11 ]); MainLoop;
But when I press the down arrow:ARG 0 = 3 ARG 1 = 2 ARG 2 = 11 ------------------
Oops? Known bug??ARG 0 = MainWindow=HASH(0x2c5c1cc) ARG 1 = 3 ARG 2 = 2 ARG 3 = 11
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Bind mishandles arguments
by Marshall (Canon) on May 31, 2011 at 08:53 UTC | |
by Anonymous Monk on May 31, 2011 at 21:44 UTC | |
|
Re: Bind mishandles arguments
by choroba (Cardinal) on May 31, 2011 at 10:43 UTC | |
by Anonymous Monk on May 31, 2011 at 21:46 UTC |