Selecting and Deselecting Stimuli

I am running PsychoPy v2023.2.3 on a Mac.

In my experiment, we provide participants 4 options on screen to choose from. We would like participants to be able to select as many answers as they would like (so they can select all 4 if they would like to), and we would like to visually represent what they have already chosen.

I have previously referred to this thread (Mouse click record selections and end routine on final “okay - #5 by Michael) to get the following code so that the boxes change to a different color upon selection, which has worked in changing the color to red:
Begin Routine:

spatial_rep_clicked = []

Each Frame:

spatial_rep_clickables = [polygonSRA, polygonSRB, polygonSRC, polygonSRD]

# check if the mouse is pressed on any of the boxes
for clickable in spatial_rep_clickables:
    if mouseSR.isPressedIn(clickable):

# change box color if clicked
for clickable in spatial_rep_clickables:
    if in spatial_rep_clicked:
        clickable.color = 'red'

I added the following code to the “Each Frame” tab in an attempt to have the color of the box change back to gray if the participant clicked it again (that is, deselected that answer as an option), but nothing happens when I run the experiment (that is, the color doesn’t change again).

# deselect option
for clickable in spatial_rep_clickables:
    if mouseSR.isPressedIn(clickable) and clickable.color == 'red':
        clickable.color = 'gray'

I also tried to use the following code in my experiment so that the names of the objects clicked at the end of the routine when the participant continues would be exported to the data spreadsheet, but I had a python syntax error despite copying the code exactly.

End Routine:

for i, clickable in enumerate(spatial_rep_clicked):
    thisExp.addData('response_' + str(i), clickable)

Insight on how to have the colors change upon selection and deselection, as well as having the names of the clicked objects when the participant continues exported to the data spreadsheet would be appreciated!

Hi There, This Youtube video might be helpful!

Hi Becca!

Thank you for your response! I actually have already watched that video and utilized some of its code, it was very helpful!

I found in another thread that you linked someone to a demo on your github of “check_multiple_clicks” (No repository · Rebecca Hirst / check_multiple_clicks · GitLab), but when I click the link, it says the file doesn’t exist. Do you have a copy of that demo by any chance?