Mouse Coordinates in Graph Window

565 views Asked by At

I'm trying to figure out how to find the mouse coordinates when clicking on the graph window a few times. So far I've tried
mx ,my = win.mouseX(), win.mouseY() and it tells me that the Nonetype is not callable. I've seen other posts involving tkinter, but I am not using that library even though I see that it's easier. Some more example code is as follows:

from graphics import *
win = GraphWin("test", 300, 300)
for i in range(3):
    win.getMouse()
    mx, my = win.mouseX(), win.mouseY()
print(mx,my)

I want the above code to have the user click on the window and print the regarding mouse coordinates. Eventually I want to store these coordinates, but I think I can figure that out.

1

There are 1 answers

0
Nathan Mills On BEST ANSWER

win.getMouse() returns a Point which you can get coordinates from like this:

from graphics import *
win = GraphWin("test", 300, 300)
for i in range(3):
    point = win.getMouse()
    mx, my = point.getX(), point.getY()
print(mx,my)