# Error while displaying text stimuli in Thai

I’m building a multilingual vocal Stroop experiment, in which the subject should name the ink color in a different language from the stimuli.
My text stimuli include Thai color words, e.g. ขาว แดง เขียว เหลือง ชมพู ม่วง เทา.

While running the experiment, the following errors were reported:

Traceback (most recent call last):
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 373, in setText
setAttribute(self, 'text', text, log)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\attributetools.py", line 141, in setAttribute
setattr(self, attrib, value)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\tools\attributetools.py", line 32, in __set__
newValue = self.func(obj, value)
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 364, in text
File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\visual\text.py", line 388, in _setTextShaders
multiline=True, width=self._wrapWidthPix)  # width of the frame
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\__init__.py", line 453, in __init__
multiline, dpi, batch, group)
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\__init__.py", line 275, in __init__
dpi=dpi, batch=batch, group=group)
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 810, in __init__
self.document = document
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 919, in _set_document
self._init_document()
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 1020, in _init_document
self._update()
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 956, in _update
lines = self._get_lines()
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 932, in _get_lines
glyphs = self._get_glyphs()
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py", line 1059, in _get_glyphs
glyphs.extend(font.get_glyphs(text[start:end]))
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\base.py", line 385, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File "C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\win32.py", line 431, in render
ord(text), ord(text), byref(abc)):
TypeError: ord() expected a character, but string of length 2 found


I have tried to change many fonts but always encounter with these errors. Sometimes, the program also generates this error:

TypeError: 'NoneType' object is not subscriptable


Is there anyway to solve this problem? How should I proceed so that PsychoPy could recognize Thai unicodes and/or Thai fonts?
Or could you recommend any font which is compatible with Thai letters?

I have no experiences with programming or with Python. Thus, any help would be really appreciated!

Have you checked whether it works with English words? I can confirm that Thai characters can work with PsychoPy

Yes, I have also created stimuli in English and German using Calibri font. There’s no problem with these two languages while running. The errors seem to occur only when displaying Thai text stimuli.

I have tried using fonts like Angsana New, Noto, Cordia New and such which are generally used with Thai letters, but always no success.

Now I’m not sure whether the problem lies in the source code or whether there is any other issue…

Please try using the newer TextBox stimulus rather than the older Text stimulus. TextBox doesn’t rely on the third-party pyglet package, which is what seems to be causing you grief here.

Thanks for your advice! Now I’m having another question regarding TextBox function.

I tried to insert parameter and conditions from an excel file by putting $color in the color field and$word in the message filed, like when I created text stimuli. It seems to not working though.

Does this function work in the same way as a text stimulus or do I have to apply some more codes in order to connect a TextBox to my parameters and conditions?

Would you please tell me which Thai font you have used at that time for generating your text stimuli?
Maybe I could try it out…

The default - Arial.

Have a look at https://run.pavlovia.org/Wake/miming/ and put t for the language.

The text is in an Excel file with one column for English and one for Thai.

We need a description of the actual problem to be able to make useful suggestions.