Text responses in python: Input() function and dialogue boxes

Thank you for the link to the related post. The suggested approach for using input() is to embed the function in a Try structure with an Exception for the EOFError as in the code below. The whole idea is to create an exception for the EOFError so that a vale is returned by the function “process_input()” and the codes keeps being executed despite coming across such error.

def process_input():
    try:
        capturedText = input("Word: ")
    except EOFError:
        capturedText = "EMPTY FIELD"
        return capturedText
    return capturedText

myText = process_input()
print(myText)

However, this does not work either.

Even though a value in the variable capturedText is correctly returned by the function process_input(), then stored in the variable myText and later on passed on to the Text component to display such text onscreen, the only value that the variable captureText can take is “EMPTY FIELD” (de defined value in case of an EOFError. Furthermore, there is no time for typing any input: After executing the code at the beginning of the routine, Psychopy proceeds to execute any lines code that may be required to be executed at every frame during the routine. This does not allow the input() function to receive a response and pass it to myText. That is why the EOFError is occurring. The function is being forced to terminate before completing.

I need that the execution of the code in Psychopy waits until a response from input is entered so that it can then be passed to the required variable for using it.

Any ideas?

I was shocked when I noticed that Psychopy does not have a built in input-text component given how needed and frequent this is for all sort of tasks. Maybe it is a feature to really think about adding in the near future?