I am trying to use graphics.py to make simple graphics that can be used as buttons. Though I know how to do this by individual drawing of each object and association to a letter or number, I am using a loop to generate the objects. I am lost on how to go about associating each object created with a specific letter or number.
Below is some code that I have been working on to attempt to find a solution to this problem. The loop functions work to create graphics as well as to detect mouse clicks in them. Where I am lost is how to assign each member of the list a specific assignment of a letter or number. The code below generates three circles that I would like to associate with letters A,B,C respectively so that when clicked, they draw the letter above the graphic.
from graphics import*
import string
def main():
window = GraphWin("Window", 400, 400)
circles1 = keys(window)
# line here to call upon function that draws labels over
# the circles using ascii string removed for relevance
# test for clicking circles
while True:
clickPoint=window.checkMouse()
if clickPoint != None:
for i in circles1:
if mouse(clickPoint, i) == True:
i.undraw()
# i.undraw used to test while loop
def keys(window):
# Define circles as an empty list
circles = []
x = 50
for i in range(3):
x += 50
circle = Circle(Point(0+x, 100), 20)
circle.setFill("black")
circles.append(circle)
circle.draw(window)
return circles
def mouse(point, circle):
x = point.getX()
y = point.getY()
radius = circle.getRadius()
center = circle.getCenter()
cx = center.getX()
cy = center.getY()
distance=(((cx-x)**2)+((cy-y)**2))**0.5
if (distance < radius):
return True
else:
return False
Ideally, clicking on a button would draw the letter it is assigned to above it. Thank you for any help