# TextBox (Beta) not displaying stimuli centred

OS Win10
PsychoPy version v. 2021 1.4

What are you trying to achieve?:

I have a simple experiment that displays words (in Thai) as stimuli in the middle of the screen. Ss then rate the words on a scale according to the dimension of interest. Everything was fine with the text component but it wouldn’t work with the Thai script. I changed to the TextBox component and it displays Thai script fine (with the appropriate font) but I cannot for the life of me get the stimulus to display in the centre of the screen.

What did you try to make it work?:

I’ve tried multiple settings in builder view. I’ve also tried using HorzAlign and HorzJust as code components but these don’t appear to do anything (the stimulus is presented in the centre of the screen but justified left; the first letter is the anchoring point from what I can tell).

It’s not a huge deal as such but when longer letter strings are presented it looks particularly awkward. I’ve attached a couple of screen shots showing the issue.

I hope there’s a solution to this. I’m quite a beginner so may be overlooking something of course.

Ben

This is the code that shows the settings (automatically generated not written by me):

# Initialize components for Routine “exptT”

exptTClock = core.Clock()
item = visual.TextBox2(
win, text=’’, font=‘Sarabun’,
pos=[0.35, -0.3], letterHeight=0.06,
size=[1, 1], borderWidth=2.0,
color=‘white’, colorSpace=‘rgb’,
opacity=None,
bold=False, italic=False,
lineSpacing=1.0,
anchor=‘center’,
fillColor=None, borderColor=None,
flipHoriz=False, flipVert=False,
editable=False,
name=‘item’,
autoLog=True,

Unfortunately this is a known issue that we’re working on, it’s actually one of the requirements we’ve set ourselves before removing the “beta” sticker from Textbox!

Oh no! There’s no way around it then. I cannot use regular text components because they will not show the Thai script.

Thanks for letting me know, anyway.

I haven’t had a problem displaying Thai script in 2020.2.10 text components

Select language = t
https://run.pavlovia.org/jasonludington/miming/html

Are the characters showing up as squares? If so it’s most likely the font - if memory serves the default font for text components is either Arial or Open Sans, which may not have glyphs for Thai characters. Try changing the font to one of these:

Oh interesting. Actually, this is from a project that my collaborator (Jason Ludington) and I were working on. You must have been the coder?

It won’t run Thai script in 2021 1.4. I’ve also tried changing the PsychoPy version in the experiment settings. I get this issue even when trying to present Thai text in a text component.

File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py”, line 942, in _get_lines
glyphs = self._get_glyphs()
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\text\layout.py”, line 1085, in _get_glyphs
glyphs.extend(font.get_glyphs(text[start:end]))
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\base.py”, line 394, in get_glyphs
self.glyphs[c] = glyph_renderer.render(c)
File “C:\Program Files\PsychoPy3\lib\site-packages\pyglet\font\win32.py”, line 432, in render
ord(text), ord(text), byref(abc)):
TypeError: ord() expected a character, but string of length 3 found

##### Experiment ended.

I can only display Thai using Textbox Beta and then it won’t centre the stimulus properly.

@TParsons - that happened previously but I changed the font as per your previous advice (to Sarabun) and it displays Thai text fine now. The issue with the Textbox component is that I cannot centre the text, which is not great for an experiment involving the presentation of letter strings.

This also means I will have issues presenting instructions in Thai.

So I’m not sure what I can do, if anything? Do I need to downgrade the Psychopy software to an older version? I don’t understand how it would work previously and not now.

Thank you

Ben

I’ve just created an instructions only version of @jasonludington’s experiment in 2021.1.4 here:

https://run.pavlovia.org/Wake/thai-test

The Thai text is still working for me in Arial.

I wondered whether it was because I was setting the text in code rather than pasting directly into the text component. However, I’ve just tested this – the firs 0.5 seconds is hard coded.

I’ll share the repro with you so you can take a look (if you let me know your Gitlab username)

Best wishes,

Wakefield

Thanks, the instruction only test is in English though? I’m trying to display different words in Thai on separate trials but I think the same issue arises whether you use a variable or just paste in the Thai text into a text component.

My workaround has been to use a textbox but that leads me to not being able to centre the text. Appreciate your help, my Gitlab username is: TUPS-lab

In the initial screen put t as the language instead of e

Thanks, that all works and displays Thai without issue in your program.

Looking forwards to seeing your solution if you can share it.

Best wishes,
Ben

There’s no such Gitlab user so I shared it with TUPS.

Thanks I was in Gitlab rather than Gitlab.pavlovia.org. It’s a bit new to me and I hadn’t realised there was a difference.

But, anyway, thanks for the files. I’ll take a closer look tomorrow and see how things are operating.

Interesting, so when I run the experiment on my machine (as a standalone psychopy expt) I get the same rendering error code! But it seems to work fine in online format i.e. the link you sent before.