Textbox first trial in Chinese and Janpanese cannot be showed

If this template helps then use it. If not then just delete and start from scratch.
textbox_q.psyexp (31.4 KB)

OS (e.g. Win10): win 10
PsychoPy version (e.g. 1.84.x): 2023.2.1
Standard Standalone? (y/n) If not then what?: y
What are you trying to achieve?: I want to use boxtext to present word in Janpanses and Chinses

What did you try to make it work?:

What specifically went wrong when you tried that?: first trial can not work
Include pasted full error message if possible. “That didn’t work” is not enough information.

Please provide more information.

Here’s a thread that mentions Japanese text.

Thank you for your help!My issue is that when I use the textbox component and assign different variables to the font of the text, as shown in the image, there is a problem when displaying Chinese or Japanese text. In the first trial of each loop, the text content becomes garbled. Occasionally, English text also experiences this issue.


Why have you picked these fonts? Have you checked they work when added directly to the textboxes? Since you are running locally, why don’t you know which platform you are using?

Chinese

if sys.platform == "win32":
    text_font = "Microsoft YaHei"  # Windows上的中文字体
    word_text = "你好";
elif sys.platform == "darwin":
    text_font = "PingFang"  # macOS上的中文字体
    word_text = "你好";
else:
    text_font = "WenQuanYi Zen Hei"  # Linux上的中文字体
    word_text = "你好";

English

# 自动选择英文字体(Windows,macOS,Linux)
if sys.platform == "win32":
    text_font = "Arial"  # Windows 上常用的英文字体
    word_text = "hello"
elif sys.platform == "darwin":
    text_font = "Helvetica"  # macOS 上常用的英文字体
    word_text = "hello"
else:
    text_font = "Verdana"  # Linux 上常用的英文字体
    word_text = "hello"

Japanese

# 自动选择字体(Windows,macOS,Linux)
if sys.platform == "win32":
    text_font = "Yu Gothic"  # Windows 上的日文字体
    word_text = "おはようございます"
elif sys.platform == "darwin":
    text_font = "MS PGothic"  # macOS 上的日文字体
    word_text = "おはようございます"
else:
    text_font = "Noto Sans CJK"  # Linux 和其他系统上的字体
    word_text = "おはようございます"

Also you have this code in Begin Experiment three times

import sys
from psychopy import visual

You don’t need them at all. Builder automatically adds code like

# --- Import packages ---
from psychopy import locale_setup
from psychopy import prefs
from psychopy import plugins
plugins.activatePlugins()
prefs.hardware['audioLib'] = 'ptb'
from psychopy import sound, gui, visual, core, data, event, logging, clock, colors, layout, hardware
from psychopy.tools import environmenttools
from psychopy.constants import (
    NOT_STARTED, STARTED, PLAYING, PAUSED, STOPPED, STOPPING, FINISHED, PRESSED, 
    RELEASED, FOREVER, priority
)

import numpy as np  # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
                   sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle, choice as randchoice
import os  # handy system and path functions
import sys  # to get file system encoding

import psychopy.iohub as io
from psychopy.hardware import keyboard

My original goal was to resolve issues with garbled text and incomplete text display across different computer systems (as shown in the image). The system I use is Windows, with PsychoPy version 2023.2.1, and there are no issues with text display on my computer. However, on another computer (with a Mac system and PsychoPy version 2023.2.3), the text appears garbled and incomplete.

PS: The font used for Japanese is MS PGothic, for Chinese is SimHei, and for English is Times New Roman.

You seem to be having two separate issues.

If you are getting a square box instead of the characters I would recommend that you change font.

If the tops and bottoms are cut off I would recommend that you try a textbox component instead of a text component.

If different fonts are needed for different languages and operating systems then it would be helpful if you can report back here which fonts you have found work on each system.