Hello
I am quite stuck on a python exercise and not quite sure how to finish it.
My task is to draw an eye using a graphics module, and when the user clicks the mouse on the eye, the program is to specify what part of the eye was clicked on, so either the pupil, white or iris, and to continue this until the user clicks outside the eye to quit the window.
I have sort of managed this but I can't get it to repeat.
def drawCircle(win, centre, radius, colour):
circle = Circle(centre, radius)
circle.setFill(colour)
circle.setWidth(2)
circle.draw(win)
def drawEye(win, centre):
for circles in range(1):
drawCircle(win, centre, 50, "white")
drawCircle(win, centre, 20, "blue")
drawCircle(win, centre, 10, "black")
def click():
win=GraphWin("Clickable eye",900, 300)
centre=Point(150,150)
for circles in range(1):
drawCircle(win, centre , 100, "white")
drawCircle(win, centre, 40, "blue")
drawCircle(win, centre, 20, "black")
p = win.getMouse()
iris1x=130
iris1y=130
iris2x=170
iris2y=170
pupil1x=110
pupil2x=190
pupil1y=110
pupil2y=190
white1x=50
white2x=250
white1y=50
white2y=250
clickx=p.getX()
clicky=p.getY()
while True:
if clickx>=iris1x and clickx <=iris2x and clicky>=iris1y and clicky<=iris2y:
message = Text(Point(200,280), "pupil")
message.draw(win)
elif clickx>=pupil1x and clickx<=pupil2x and clicky>=pupil1y and clicky<=pupil2y:
message = Text(Point(150,280), "Iris")
message.draw(win)
elif clickx>=white1x and clickx<=white2x and clicky>=white1y and clicky<=white2y:
message= Text(Point(150,280), "white")
message.draw(win)
else:
win.close()
If anyone could help me get this to work and simplify it I would be greatly thankful.