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;
}