How could I call function by clicking in the graphics window. I currently have a draw eyes function but i want to be able to call it by clicking on the graphics window and call 30 eyes in the same colour sequence of blue, green and brown? so i could plot the eyes on chosen centre points of the graphics window?
from graphics import *
eye_colours = set("""green brown blue""".strip().split())
def drawCircle(win, centre, radius, colour):
circle = Circle(centre, radius)
circle.setFill(colour)
circle.setWidth(2)
circle.draw(win)
def eyePicker():
while True:
colour = raw_input("Please enter the colour: ").strip()
colour = colour.lower()
if colour in eye_colours:
return colour
else:
print("Invalid colour '{0}'.".format(colour))
print("Possible values are {0}".format(tuple(eye_colours)))
def drawEye():
w = 250
h = 250
win = GraphWin("Eye", w, h)
try:
# center should be at 1/2 width and height
centre = Point(w//2, h//2)
colour = eyePicker()
drawCircle(win, centre, 40, colour)
drawCircle(win, centre, 20, colour)
drawCircle(win, centre, 10, colour)
win.getMouse()
finally:
win.close()
drawEye()
def eyesEverywhere():
w = 500
h = 500