Mouse click location on a scrolled canvas 
Author Message
 Mouse click location on a scrolled canvas
Hello,

I have a Scrolled Canvas, and would like to get the cursor location
relative to the canvas (not the scrolled region). Is there an easy way
to do this?

Thanks



Mon, 03 Oct 2005 03:13:22 GMT  
 Mouse click location on a scrolled canvas
duh, I'll read the man pages more carefully next time.

$canvas->canvas{x,y}

Quote:

> Hello,

> I have a Scrolled Canvas, and would like to get the cursor location
> relative to the canvas (not the scrolled region). Is there an easy way
> to do this?

> Thanks



Mon, 03 Oct 2005 04:14:09 GMT  
 Mouse click location on a scrolled canvas
Here is some code that I have used to get canvas coordinates of
the mouse cursor:

Here's a binding call to specify that the "Trap_cursor" function should be
called when the left mouse button is clicked over the canvas ... whose
Widget Id
is in the $Scratchpad variable.

  $Scratchpad->CanvasBind("<B1-ButtonRelease>",
                    [\&Trap_cursor, $Scratchpad,
                    "Cursor_red", "Cursor_text_red"]);

Here's the argument interface for the "Trap_cursor" callback function. Note
the
$Id. This is a Widget ID that Tk provides as part of the function call. In
this case
it is the WIdget Id of the canvas.

sub Trap_cursor
{

These lines get the X and Y canvas coordinates of the
point that the cursor is over when the left mouse
button is clicked.

  $X = $Id->canvasx($Id->XEvent()->x);
  $Y = $Id->canvasy($Id->XEvent()->y);

I got some of this information from the official documentation, but
some of it is from trial and error experimentation. I can't
remember which came from where ... try this out and see
if it works.

Gary Krohmer



Quote:
> Hello,

> I have a Scrolled Canvas, and would like to get the cursor location
> relative to the canvas (not the scrolled region). Is there an easy way
> to do this?

> Thanks



Tue, 04 Oct 2005 06:23:33 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. tying a widget in one canvas to the scrolling of another canvas

2. simulating a mouse click?

3. Sending keystrokes and mouse click under WinPerl

4. anyone know how to simulate a mouse click?

5. Mouse Click Bind for an Entry Widget

6. Simulating mouse clicks on other GUI programs

7. binding mouse clicks to Tk::Columns

8. left mouse click on HList throws messages when empty

9. A weird one - misguided mouse clicks and all that

10. mouse right click

11. Please help: Binding mouse click to tree entry.

12. binding right mouse button click to all buttons

 

 
Powered by phpBB® Forum Software