| Reference | Downloads | Github

Displaying keyboard input using textBox

OS (e.g. Win10): MacOS
PsychoPy version (e.g. 1.84.x): 1.85.4
Standard Standalone? (y/n) Yes
What are you trying to achieve?: Update and display keyboard input in textBox

What did you try to make it work?:
I was having the same problem occurring in the link below (psychopy crashing with keyboard input):!topic/psychopy-users/WsDp_w485w4
The comments on the thread above wrote that textBox is more stable than textStim, so I was trying to
use textBox in the code component within the builder.
However, I couldn’t find a way how to update keyboard input using textBox.
I did create a textbox using the code below in the begin experiment section:

text = ‘default text’,
font_size =30,

I also created the objects below in the begin experiment section:
word = “Type what you heard”
inputText = “” -> this is the object that changes with every keyboard input

However, when I added the line below in the each frame section
textbox.setText(word + ‘\n’ + inputText)

I got an error message.

What specifically went wrong when you tried that?:

Below is the error message:

textbox.setText((word + ‘\n’ + inputText))
TypeError: ‘str’ object is not callable
Exception RuntimeError: RuntimeError(‘sys.meta_path must be a list of import hooks’,) in <bound method ExperimentHandler.del of < object at 0x1107eaed0>> ignored

Has anyone succeeded in updating keyboard input and showing that in the textBox?

Hi @seedee, I am unable to recreate your error in the most recent version of PsychoPy (although I am using a Windows PC). Are you able to try again with the latest version of PsychoPy?

Hello @dvbridges, thank you for reading and commenting. I just updated to PsychoPy ver 1.90.1 and strangely after updating, the experiment doesn’t even start when I push the run button.

Ok, there is a more recent version than 1.90.1, you could try version 3.0.0b11, which is what I am using. Also, are there any error messages at all? Can you try and run the script from Coder and see if an error appears in the console at the bottom of the window?

I downloaded 3.0.0b11 and ran the experiment and below is the error message I have:
(Do I have to rebuild the script from the builder if I download a newer version? When I run the same script on 1.85.4, it runs but gives me the error message I wrote in the post in the middle of the experiment. But the script doesn’t start and gives the the error message write away for 3.0.0b11)

5.0772 WARNING User requested fullscreen with size [1024 768], but screen is actually [1440, 900]. Using actual size
2018-10-18 13:58:12.025 python[2304:55806] ApplePersistenceIgnoreState: Existing state will not be touched. New state will be written to (null)
Traceback (most recent call last):
File “freetype/raw.pyc”, line 49, in
File “ctypes/init.pyc”, line 348, in init
OSError: dlopen(libfreetype.dylib, 6): image not found

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/Users/rimjaynor/Desktop/Psychopy_181002/”, line 99, in
File “/Applications/”, line 119, in call
obj = object.getattribute(self, ‘_resolve’)()
File “/Applications/”, line 88, in _resolve
obj = factory(self, scope, name)
File “/Applications/”, line 203, in _import
module = import(module_python_path, scope, scope, [member], level=0)
File “/Applications/”, line 37, in
from .fontmanager import FontManager
File “/Applications/”, line 21, in
from freetype import Face, FT_LOAD_RENDER, FT_LOAD_FORCE_AUTOHINT, FT_Exception
File “”, line 961, in _find_and_load
File “”, line 950, in _find_and_load_unlocked
File “”, line 646, in _load_unlocked
File “”, line 616, in _load_backward_compatible
File “freetype/init.pyc”, line 21, in
File “”, line 961, in _find_and_load
File “”, line 950, in _find_and_load_unlocked
File “”, line 646, in _load_unlocked
File “”, line 616, in _load_backward_compatible
File “freetype/raw.pyc”, line 52, in
RuntimeError: Freetype library not found

I have also attached my script just in case.
test.psyexp (16.4 KB)

I believe the original problem is due to your code component in the routine “practice_intel”. You have overwritten the function setText with a string:

if textbox.setText != word + '\n' + inputText:
    textbox.setText = word + '\n' + inputText

and then tried to call that function which no longer exists, as it is a string:

textbox.setText((word + '\n' + inputText))

You will need to change the first bit of code above to:

if textbox.setText != word + '\n' + inputText:
    textbox.setText(word + '\n' + inputText)

I think you are also missing the draw() function, add that after you set text to see the text on screen.

Thank you so much @dvbridges !
I have changed the code to

if textbox.draw() != word + '\n' + inputText:
    textbox.setText(word + '\n' + inputText)

and added


and now my textbox shows keyboard input as I type on the keyboard!
Strangely my textbox only displays part of the text but I think I’d be able to fix that easily.
Again, I really appreciate your help.


Hi @seedee,

I tried updating the code you posted following the feedback given after it, but can’t seem to get code that will run. Could you possibly post a working copy of your script? It seems like this features is something that many people are looking for, including myself, but there are no full and working implementations posted that I can find.