# Save textbox text when no answer is given

**URL:** <https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782>\
**Category:** Builder\
**Tags:** online\
**Created:** [October 9, 2025, 2:39pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782 "2025-10-09T14:39:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [October 9, 2025, 2:39pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/1 "2025-10-09T14:39:43Z")

</div>

**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.

```auto
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.

```auto
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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 10, 2025, 8:00pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/2 "2025-10-10T20:00:02Z")

</div>

> [@JensBoelte](#):
>
> `thisExp.addData("Keine Antwort", textboxBericht.text)`

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

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

```

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [October 11, 2025, 1:51pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/3 "2025-10-11T13:51:07Z")

</div>

Hello @wakecarter

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

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

```

does not work. The data column`Antwort` 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

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

```

The data column `textboxBericht.text`contains the provided answer.

The `elif`condition works as intended.

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

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

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

```

the other in an `End routine`tab

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

```

Best wishes Jens

---

<div class="post-metadata">

**Author:** ![JensBoelte](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/jensboelte/32/9060_2.png) [@JensBoelte](https://discourse.psychopy.org/u/JensBoelte)\
**Post date:** [October 11, 2025, 2:02pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/4 "2025-10-11T14:02:58Z")

</div>

Hello

this now works. In the `Begin routine`tab

```auto
if skip:
    continueRoutine = False

```

and in the `End routine`tab

```auto
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

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 11, 2025, 2:09pm UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/5 "2025-10-11T14:09:57Z")

</div>

> [@JensBoelte](#):
>
> textboxBericht.text

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.

---

<div class="post-metadata">

**Author:** ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)\
**Post date:** [October 12, 2025, 9:27am UTC](https://discourse.psychopy.org/t/save-textbox-text-when-no-answer-is-given/45782/6 "2025-10-12T09:27:24Z")

</div>

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.

> [@Wakefield's Daily Tips](https://discourse.psychopy.org/t/wakefields-daily-tips/43371/117):
>
> Setting the contents of an editable textbox If you want participants to be able to type into a textbox but edit the contents of the textbox.text column in the data file, you will need to make the edit in Each Frame code as the routine is ending. This is an exception to the rule that code components should go at the top of the routine. For this to work I would recommend putting this code component at the bottom since it will need to go below both the textbox component and the component or code t…
