Adding Button Components

OS (e.g. Win10): Windows 11 Pro
PsychoPy version (e.g. 1.84.x): v2023.1.2
Standard Standalone? : Y
What are you trying to achieve?:

I am trying to add button components to each routine in my experiment so that it can be run on touchscreen phones.

I would like people to be able to press:

  1. NEXT after the information page
    => then move onto…
  2. YES or NO for consent
    => then move onto…
  3. YES or NO to confirm they are 18 or over
    or a goodbye page if they said no to consent
    => then move onto…
  4. NUMBERS for their age
    (this should accept multiple button presses, saved in order, without ending the routine)
    and NEXT to move onto the next question
    or a goodbye page if they said no to being 18 or over
    => then move onto…
  5. YES or NO for whether they have elder siblings
    => then move onto…
  6. YES or NO for whether English is their first language
    => then move onto…
  7. NUMBERS for how many languages they speak in total
    (this should accept multiple button presses, saved in order, without ending the routine)
    and NEXT to move onto the next question
    => then move onto…
  8. NEXT after the introduction to the trials
    => then move onto…
  9. REAL or NOT REAL buttons for the word classification task with 52 words
    (the word list is in a separate excel conditions file - it should have a REAL vs NOT REAL button for
    each word and when answered it should move to the next word)
    => then move onto…
  10. SUBMIT after the debrief

What did you try to make it work?:

I tried to add a button component but the information page provided by PsychoPy doesn’t give a step by step on adding and coding for buttons. I do not know what callback function to add for the code, and I cannot find PsychoPy related tutorials.

I also do not know how to set the buttons to work for the NUMBERS or for the REAL vs NOT REAL buttons on word trials.

I then tried to add a textbox and mouse component but I did not understand how to add the code so it would not appear when I ran the experiment - regardless, a button component would be ideal as it is a shortcut.

If anyone is able to advise me on adding these buttons, it would be very helpful :slight_smile:

If you have a YES button for elder siblings then your callback function could be elder = 1 (or yes). expInfo[‘eldersiblings’] = True might also work, or even thisExp.addData(‘elderSiblings’,‘Yes’) though that last one might fail in translation to JS online.

Hi there,

Thank you for the suggestion - I attempted these but the button did not appear for the elder siblings question when I would do a run of the experiment on PsychoPy.

I will be using the keyboard component instead and asking that participants carry out the experiment on laptops/computers instead, or somehow adding the keyboard component to smartphones.

Do you know if there is a way for the keyboard response component to be used on touchscreen devices (e.g., smartphones)?

I use mouse responses with image and text components (not buttons) for touchscreen.