Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+2 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 (5.1k points)

2 Answers

+2 votes

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

answered by (2.6k points)
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 (4.2k points)
...