Using a checkbox in psychopy

Is there a way to use checkboxes in PsychoPy?

In the context of an experiment I would like to have one page, where the experimenter chooses one or several from a set of experiment-parts that shall be executed.

This could be achieved with the “Form” module in the builder. The drawback of this solution is that one would need to indicate yes/no or each experiment-part. I’d prefer to simply check on checkboxes.

1 Like

@Guido_Biele, creating checkboxes can be done using shapes and code. See the attached for an example.

checkbox.psyexp (14.2 KB)

4 Likes

Hi @dvbridges, I’m trying to use checkboxes for my online study. I used your example as a template, but I can’t figure out how it is possible for participants to uncheck a box, if it was checked unintentionally. Could you try to help me with that?
And will this example also work on Pavlovia?

Thanks a lot!

2 Likes

Hi @dvbridges,
I’m trying to use a checkbox in a loop (for an offline experiment). Your code worked well but if the checkbox has been ticked once, it appears as ticked on every next iteration of the routine.
Would you know how to fix that? That is, how to draw an unticked checkbox at each iteration of the loop independently of if it was checked previsously?
Many thanks for any advice!

hi @Ambre_Denis-Noel,

Yes, just add the following code to the code component, to change the color back to the default. Add the code to the “Begin Routine” tab, so it looks like:

checkboxes = [box1, box2, box3]
clicked = []
for box in checkboxes:
    box.color = "white"
1 Like

Ahahah ^^ Easier than I thought! Thanks!
I also have a continue button that I would like to enable only if a slider component has been rated OR if the checkbox has been ticked.
I tried

 if my_slider.getRating() is not None or mouse.isPressedIn(box):
    continueButton.buttonEnabled = True

But it does not work at all (the script crash).
I do not wish to take your time but if you have any idea…

Thx!

@Ambre_Denis-Noel, not sure without seeing all the code, but here is another version of checkBox with the functionality you need:

checkbox.psyexp (16.4 KB)

1 Like

Wonderful!!
Thanks!

Hi, @dvbridges Is this also possible to uncheck a checked box?