Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+4 votes

I created a list of buttons in my graphics window and I'm trying to get the buttons to activate, but no matter where I click in my window, Python says that I'm not clicking inside any buttons and they won't activate.

while not ready:
clickPt = win.getMouse()
for button in buttonList:
    if button.isClicked(clickPt):
        button.activate()
asked in CSC201 Spring 2021 by (1 point)

2 Answers

+2 votes

You should try to activate the button after you created it rather than after you click on it

answered by (1 point)
0 votes

The button should be activated right after you make and draw the button, and before getting a click from the mouse.

Ex:

button = Button(Point(10,10),10,10,"Button")
button.draw(window)
button.activate()
ready = False
while not ready:
    clickPt = win.getMouse()
    if button.isClicked(clickPt):
       ready = True

Hope this helps!

answered by (1 point)
...