Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl tk canvas events hiding

Status
Not open for further replies.

ori1139

Programmer
May 16, 2011
3
IL
Hi.
I'm new to PerlTk.
What I'm trying to achieve is getting the message "oval was pressed" even when I press the rectangle.

Below there a simplified version of the code.

require v5.8.5;

use Tk;
my $window = MainWindow->new;
my $drawing = $window->Canvas(-width => 400, -height => 300, -background => "white") -> pack;

$ov = $drawing->createOval(100,50,300,250,-fill=>"black");
$rec = $drawing->createRectangle(150,100,250,200,-fill=>"white");

$drawing-> bind( $ov, '<Button-1>',sub{$window -> messageBox(-type=>"ok", -message=>"oval was pressed");});

MainLoop;


Thanks!
 
Wouldn't you just need an additional bind?
Code:
$drawing-> bind( [u]$rec[/u], '<Button-1>',sub{$window -> messageBox(-type=>"ok", -message=>"oval was pressed");});
 
The code I've posted is just a simplified version of what I really need to do.

What I'm really trying to do is to draw a map with layer of information. The problem is that for example lines from the grid of the map hide events from the layer beneath them.


Thanks

Ori
 
Haven't worked with canvas's much but this idea may work:

Instead of putting the bind on the shape, add a bind to the canvas. The routine the canvas calls can pick up your @x,@y values and map that against the area with in all of your shapes. Wouldn't be efficient, but would get things done if you don't have 1000's of shapes.

I don't know if the canvas widget provides a calculator that will provide a clean yes/no to this (I'm thinking of the TclTk's text widget that does provides a comparable function) The mathematical formulas to calculate this on the fly aren't too bad, but could be problematic to maintain if your shapes become non-geometrical.
 
This is eventually what I did. I was just wondering if there is some other more elegant way to do it. Any way this is the way I calculated the corrected position of y-Axe:



$self->{canvas}->CanvasBind("<Button-3>", [ \&popup_menu, Ev1('%y') ]);

sub popup_menu
{
my ($canv, $y) = @_;
my $offsetY = $canv->canvasy(0);
$corrected_y =$offsetY+ $y;
print "popup corrected y ".$corrected_y;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top