Repost: Psychopy Questionnaire with Polygons

Dear all,

This is a repost, as previous comments unfortunately could not help me further: Clicking polygons for questionnaire

I have made questions with multiple choice answers and I have put the multiple choice answers in polygons. I have done so because I want to test the participants on their knowledge of the instructions. I have made two routine screens where one of them holds 6 questions and the next 5 questions. I want participants to fill answers, where they can at the last moment check whether they had them right.

I have two problems:

First problem:
I am able to let participant click on answers and unselect them: the colour changes to red when selected and to white when unselected. However, when clicked the selected polygons will flicker from red to white. I think it is the same problem as in this thread: Stimuli changes colour when clicked but ‘flickering’ and not responding immediately
I cannot seem to apply it to my experiment somehow, this is my code:

Each frame:

polygons = [rec_1_a, rec_1_b, rec_1_c, rec_2_a, rec_2_b, rec_3_a, rec_3_b, rec_4_a, rec_4_b, rec_4_c, rec_5_a, rec_5_b, rec_5_c, rec_6_a, rec_6_b]

for i in polygons:
    if mouse.isPressedIn(i) and i.fillColor != "red":
        i.fillColor = "red"
    elif mouse.isPressedIn(i) and i.fillColor != "white":
        i.fillColor = "white"

My second problem:

I would like to say that if one of the answers in question 1 (rec_1_a, rec_1_b, rec_1_c) is selected, the others ones must be unselected, so you can only select one answer for a given question.

If somebody could help me further it would be much appreciated.

Best,

Snoek

for i in polygons:
    if mouse.isPressedIn(i) and i.fillColor != "red":
        i.fillColor = "red"
        pressed = i
    elif pressed != i:
        i.fillColor = "white"

This should only allow one rectangle to be pressed but won’t allow a reset to nothing pressed. Set pressed = 99 in Begin Experiment

The principle I use for separating clicks is checking the coordinates. If the coordinates are identical, it’s probably not a new click.

1 Like

Dear wakecarter,

Thank you very much for replying to my post again. This answer helped me out a lot and in all my excitement I forgot to reply to you. Thank you for this great help, it is much appreciated.

Best regards,

Snoek