sub marker{ my($id, $mouseX, $mouseY) = @_; # get offset of window to underlyling canvas my $offsetX = $window->canvasx(0); my $offsetY = $window->canvasy(0); my $color = '#800000'; my @items = $id->find('withtag', 'mark'); # if marker exists, move it to new position if ($items[0]){ my $moveX = $mouseX - ($markX - $offsetX); my $moveY = $mouseY - ($markY - $offsetY); for (@items){$id->move($_, $moveX, $moveY)} # or else create marker }else{ $id->create(('line', $mouseX, $mouseY-20, $mouseX, $mouseY+20), -fill => $color, -tags => ['mark'],); $id->create(('line', $mouseX-20, $mouseY, $mouseX+20, $mouseY), -fill => $color, -tags => ['mark'],); } # calculate new absolute position of marker $markX = $mouseX + $offsetX; $markY = $mouseY + $offsetY; }