#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); # first create a canvas widget my $canvas = $mw->Canvas(width => 300, height => 200)->pack(); my $one = $canvas->createOval(55, 20, 200, 190, -fill => 'blue', -outline=>'blue', -tags => ['blue'], ); my $two = $canvas->createOval(105, 20, 250, 190, -fill => 'red', -outline=>'red', -tags => ['red'], ); my $ebutton = $mw->Button(-text => 'Exit', -command => 'Tk::exit')->pack(); $canvas->Tk::bind("", [ \&print_xy, Ev('x'), Ev('y') ]); MainLoop(); sub print_xy { my ($canv, $x, $y) = @_; #trick to simulate a 1 point rectangular area my (@current) = $canvas->find('overlapping', $x, $y, $x, $y); foreach my $id(@current){ print $canvas->gettags($id),' '; } print "\n"; } __END__