Chinese input error of TextBox2


I’m trying to conduct an online experiment and I have to create procedures that can be run on both Windows and MacOS system computers. I use TextBox2 component to enable participants to write essays. The component works on a Windows system computer, even if I input multiple Chinese characters at the same time. But when I input multiple Chinese characters on a MacOS system computer, some errors happen.

Traceback (most recent call last):
  File "_ctypes/callbacks.c", line 234, in 'calling callback function'
  File "/Applications/", line 1128, in objc_method
    result = f(py_self, *args)
  File "/Applications/", line 78, in insertText_
    self._window.dispatch_event("on_text", text)
  File "/Applications/", line 1333, in dispatch_event
    if EventDispatcher.dispatch_event(self, *args) != False:
  File "/Applications/", line 415, in dispatch_event
    if getattr(self, event_type)(*args):
  File "/Applications/", line 429, in onText
  File "/Applications/", line 966, in _onText
  File "/Applications/", line 410, in addCharAtCaret
  File "/Applications/", line 483, in _layout
    if self._styles[i] == NONE:
IndexError: list index out of range
Traceback (most recent call last):
  File "/Users/weiziqian/OneDrive/Documents/py_project/exp1/writing_control/exp_MacOS/", line 52, in <module>
  File "/Users/weiziqian/OneDrive/Documents/py_project/exp1/writing_control/exp_MacOS/", line 155, in run_writing_task
    words = removePunctuation(textbox.text)
  File "/Applications/", line 360, in text
    if styles[i] == ITALIC and lastFormatter != styles[i]:
IndexError: list index out of range

In addition, it seems TextBox2 cannot insert line break automatically.

Any help is appreciated.

Computer system: MacOS Monterey 12.0.1
PsychoPy version: StandalonePsychoPy-2021.2.3-macOS


Hi, you can change font to Hiragino Sans GB or Arial Unicode MS. You might find useful information on [chinese mac] Fonts

We made some substantial changes to TextBox2 in v2022.1.0, particularly in the _layout method where your error is happening, so it may be worth upgrading to the latest version. If you do so, does this still occur?

Thanks for the information. I have downloaded the latest version but the same error is still occurring in the MacOS system. Fortunately, my scripts work fine in the Windows system. So I think this error might just be a computer system issue.

1 Like

Interesting - I’m not surprised that the call to removePunctuation causes problems on Mac as Mac’s do some smart substitution which can mess with that sort of thing, but it’s strange that the ._styles array is a different length between Mac and Windows. Could you share the specific characters you’re using which cause the error? We have a Mac in the office so I’d like to test this out and see what’s going on

Hi, I’m glad to help. It looks like whenever you try to type multiple Chinese characters the issue will occur. For example, you can try to type 计算机 (the input code is jisuanji). Before trying this, you need to set up a Chinese input source on your Mac.