Text does not wrap using either TextStim or TextBox

OS (e.g. Win10): Win 10, version: 1909
PsychoPy version (e.g. 1.84.x): PsychoPy 2021.1.1
**Python version: 3.8.8
Standard Standalone? (y/n) n

Apologies if I missed some key informaiton, but I did not find a solution on the forum.
I really appreciate any advice.

What are you trying to achieve?:
I’m using spyder to bulid an experiment with text stimuli to get participants’ responses.
My codes are as follows:

#%% constants of all experiments
DISPSIZE = (800,600)
FGC = (-1, -1, -1)
BGC = (0, 0, 0)
disp = visual.Window(size = DISPSIZE, units = 'pix', color = BGC)
# constants of this experiment
CS = pandas.read_csv('C:/psychopy/FormalExperiment_testing1/FinalMaterials/CS.csv', \
                     encoding='utf-8',header=0, skip_blank_lines=True)
CS = CS.dropna(axis=0)
cs = CS.to_numpy()
R_AC = pandas.read_csv('C:/psychopy/FormalExperiment_testing1/FinalMaterials/randomised_AC.csv', \
                       encoding='utf-8')
## dropna: 0 = delete NaN by row, 1 = by column
R_AC = R_AC.dropna(axis=1)
r_ac = R_AC.to_numpy()
#%% create the coverstory
for i in range(len(cs)):
    coverstory = visual.TextStim(disp, text = cs[i,2], height=15, color=FGC, \
                                wrapWidth=200, pos=(0,0))

What specifically went wrong when you tried that?:
The texts (extracted from a .csv file) are only partially dipslayed in a single line, despite I set wrapWidth=200. I also tried TextBox component, but the result is the same.


(You may notice that the sentence is in Chinese and the last character on the screen is not intact.
The texts are made out of sequences of Chinese characters with no space in between.)

I googled a lot but there is little information on textbox or wrapwidth on the Internet. I tried codes of TextStim from this website https://www.djmannion.net/psych_programming/vision/tog/tog.html with wrapWidth set and their program worked. But when I changed mine, it failed nevertheless.
here’s the code from the above website.

win = psychopy.visual.Window(
    size=[400, 400],
    units="pix",
    fullscr=False
)

sfm_stim = psychopy.visual.ElementArrayStim(
    win=win,
    units="pix",
    nElements=sfm_n_dots,
    elementTex=None,
    elementMask=sfm_dot_shape,
    sizes=sfm_dot_size_pix
)

instructions = psychopy.visual.TextStim(
    win=win,
    wrapWidth=350,
)

instructions.text = """
Press the left arrow key when you see the front surface rotating to the left.\n
Press the right arrow key when you see the front surface rotating to the right.\n
\n
Press any key to begin.
"""

instructions.draw()
win.flip()

I also noticed a suggestion for degrading pyglet to 1.3.2 (my previous version is 1.4), but it is not compatible with other packages.

I added several space to the texts hoping the program would identify where the text should wrap. Did not work as well.

wrapWidth is specified as number of characters - if it’s set to 200, then this should wrap after 200 characters, whereas it doesn’t look like you have that many. If you set it to a small number that’s easily visible (say 4), does it wrap then?

If you use TextBox2, then you can set the .size and .pos properties as you would a Rect and it should wrap to within that box.

1 Like