1

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.

Nathan Mills
  • 2,243
  • 2
  • 9
  • 15
IcyG
  • 19
  • 4
  • You're using the Zelle graphics.py library, right? Please tag with "zelle-graphics" if so. – Nathan Mills Mar 22 '22 at 00:24
  • you should put `print()` inside `for`-loop to display all postions. OR you will have to add them to list - if you want to use them to draw some figure. – furas Mar 22 '22 at 01:07
  • it seems Zelle graphics.py doesn't have functions `mouseX()`, `mouseY()`. Where did you get from? – furas Mar 22 '22 at 01:13

1 Answers1

2

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)
Nathan Mills
  • 2,243
  • 2
  • 9
  • 15