Save textbox text when no answer is given

OS (e.g. Win10):
PsychoPy version (e.g. 2025.1.0 Py 3.10):
Standard Standalone Installation? (y/n) Y
Do you want it to also run online? (y/n) Y
What are you trying to achieve?:

I am updating my change blindness experiment so that it uses the textbox component to save written answers instead of using code. Textbox answers are saved. However, sometimes participants either do not recognise the change or do not provide an answer. Currently, nothing is saved in these cases. I would like to save the strings ‘kein Erkennen’ when no change is detected and ‘keine Antwort’ when no answer is given.

I added the following code to the ‘Begin’ tab of the routine where participants provide their answers.

if skip:    #no change was detected
    thisExp.addData("kein Erkennen", textboxBericht.text)
    continueRoutine = False

I have the following code in the end tab of the same routine for cases when no answer was given.

if len(textboxBericht.text) == 0:
    thisExp.addData("Keine Antwort", textboxBericht.text)

Unfortunately, the column textboxBericht.text in my data is empty in both cases.

Suggestions are heartly welcome.

Best wishes Jens

This is saving nothing into a column called Keine Antwort. How about:

if textboxBericht.text:
     thisExp.addData('Antwort', textboxBericht.text)
elif skip:
     thisExp.addData('Antwort', 'Keine Erkennen')
else:
     thisExp.addData('Antwort', 'Keine Antwort')

Hello @wakecarter

Thanks a lot for the input. I tried this but the line

if textboxBericht.text:
   thisExp.addData('Antwort', textboxBericht.text)

does not work. The data columnAntwort had always the value keine Antwort when an answer is provided. This is probably due the fact that I call this code-component in the same routine as the component textboxBericht. In this case the if-else construction evaluates to

else:
     thisExp.addData('Antwort', 'Keine Antwort')

The data column textboxBericht.textcontains the provided answer.

The elifcondition works as intended.

It seem to be impossible to set the value of textboxBericht.text

Currently, everything is in a Begin routinetab. I think about splitting the if-else construction in two parts, one in a Begin routinetab

if skip:
     thisExp.addData('Antwort', 'Kein Erkennen')
     continueRoutine = False

the other in an End routinetab

if textboxBericht.text:
     thisExp.addData('Antwort', textboxBericht.text)
else:
     thisExp.addData('Antwort', 'Keine Antwort')

Best wishes Jens

Hello

this now works. In the Begin routinetab

if skip:
    continueRoutine = False

and in the End routinetab

if textboxBericht.text:
    thisExp.addData('Antwort', textboxBericht.text)
elif skip:
    thisExp.addData('Antwort', 'Kein Erkennen')
else:
    thisExp.addData('Antwort', 'Keine Antwort')

It would be even better if I could save the responses in textboxBericht.text.

Best wishes Jens

You should be able to do textboxBericht.text = “No answer” but for it to be saved I’m wondering whether it needs to be set in the final frame instead of End Routine.

1 Like

I’ve just confirmed this morning that you need to set textbox.text in Each Frame as the routine is ending. I’ve added it to my top thread.

1 Like