Wakefield's Daily Tips

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 that is ending the trial.

The following code will set textbox.text as “Empty” if the routine ends with a blank textbox.

Each Frame

if continueRoutine == False:
    if not textbox.text:
        textbox.text = "Empty"

Note that any component that forces a routine to end, sets the variable “continueRoutine” to False. This variable is checked at the end of each frame.

2 Likes