Thread canvas rect item callback Frage (5 answers)
Opened by FoolAck at 2009-01-11 21:51

Spieler
 2009-01-12 01:55
#117862 #117862
User since
2007-09-24
70 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use strict;
use warnings;
use Tk;

$|++;

my $data = {
pressed => 0,
};

my $mw = MainWindow->new();
my $canvas = $mw->Canvas(-width => 200, -height => 200)->pack();
my @items;
for my $x (1 .. 4) {
my $x1 = $x * 25;
my $y1 = $x1;
my $x2 = $x1 + 25;
my $y2 = $y1 + 25;

$items[$x - 1] = $canvas->createRectangle($x1, $y1, $x2, $y2, -fill => 'red', -width => 0);
}

$canvas->Tk::bind( '<B1-Motion>', [\&b1_motion,Tk::Ev('x'),Tk::Ev('y')]) for 0 .. 3;
MainLoop();

sub b1_motion{
my ($c,$x,$y) = @_;
my $item_id = $c->find('overlapping',$x,$y,$x,$y);
$item_id = defined $item_id ? $item_id->[0] : '';
print "processing item $item_id\n" if $item_id;
}

Meinst du so etwas?

Grüße, Christoph

View full thread canvas rect item callback Frage