# Error while displaying text stimuli in Thai

**URL:** https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474
**Category:** Coding
**Tags:** font, unicode, text
**Created:** [November 27, 2020, 8:22pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474 "2020-11-27T20:22:38Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![wlannnnn](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wlannnnn](https://discourse.psychopy.org/u/wlannnnn)
#### Post date: [November 27, 2020, 8:22pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/1 "2020-11-27T20:22:38Z")

</div>

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:

```auto
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
    self._setTextShaders(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:

```auto
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!

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [November 27, 2020, 10:34pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/2 "2020-11-27T22:34:52Z")

</div>

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

---

<div class="post-metadata">

### Author: ![wlannnnn](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wlannnnn](https://discourse.psychopy.org/u/wlannnnn)
#### Post date: [November 27, 2020, 11:00pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/4 "2020-11-27T23:00:01Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [November 27, 2020, 11:18pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/5 "2020-11-27T23:18:03Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![wlannnnn](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wlannnnn](https://discourse.psychopy.org/u/wlannnnn)
#### Post date: [November 28, 2020, 11:54am UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/8 "2020-11-28T11:54:42Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![wlannnnn](https://avatars.discourse-cdn.com/v4/letter/w/edb3f5/32.png) [@wlannnnn](https://discourse.psychopy.org/u/wlannnnn)
#### Post date: [November 28, 2020, 9:39pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/9 "2020-11-28T21:39:10Z")

</div>

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…

---

<div class="post-metadata">

### Author: ![wakecarter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/wakecarter/32/5753_2.png) [@wakecarter](https://discourse.psychopy.org/u/wakecarter)
#### Post date: [November 28, 2020, 10:54pm UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/10 "2020-11-28T22:54:49Z")

</div>

The default - Arial.

Have a look at [https://run.pavlovia.org/Wake/miming/](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.

---

<div class="post-metadata">

### Author: ![Michael](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/michael/32/16_2.png) [@Michael](https://discourse.psychopy.org/u/Michael)
#### Post date: [November 29, 2020, 12:39am UTC](https://discourse.psychopy.org/t/error-while-displaying-text-stimuli-in-thai/18474/11 "2020-11-29T00:39:35Z")

</div>

> [@wlannnnn](#):
>
> It seems to not be working though.

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