Now I would like to be able to move the rectangle on the diagonal by pressing for example both up and right. To write:#!/usr/bin/perl -w use Tk; use strict; my $mw = MainWindow->new; my $c = $mw->Scrolled('Canvas', -width => 200, -height => 200, -background =>'blue', -scrollregion => [ 0, 0, 500, 500 ] ); $c->pack(-expand => 1, -fill => 'both'); my $rect=$c->createRectangle(100, 100, 150, 150, -fill => 'yellow'); + $mw->bind('<KeyPress-Left>', sub{$c->move($rect, -5, 0);}); $mw->bind('<KeyPress-Right>', sub{$c->move($rect, 5, 0);}); $mw->bind('<KeyPress-Up>', sub{$c->move($rect, 0, -5);}); $mw->bind('<KeyPress-Down>', sub{$c->move($rect, 0, 5);}); my @coords_list = $c->coords($rect); MainLoop;
..is however not possible do you have any other suggestions how to bind two arrowkeys to an event?$mw->bind('<Right-KeyPress-Up>', sub{$c->move($rect, 5, -5);});
In reply to Re^4: Tk: Binding Keys to events
by tamaguchi
in thread Tk: Binding Keys to events
by tamaguchi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |