| Reference | Downloads | Github

Problem with text formatting using Text stimuli in PsychoPy builder

I am running PsychoPy2 version 1.90.2 (and have also tried this on PsychoPy2_PY3 version 1.90.1) using standard standalone on Win10.

I am building a simple experiment where I will show participants images and ask them to respond to them using the keyboard. During the trials I want to show them a rating scale at the bottom of the screen, under the image, to remind them of the response options. Under the numeric scale I want to display text to explain what both of the extreme options represent:

However, despite putting the scale and the description of the response options on different lines in the builder, they show up on the same line separated by an unknown character rather than on separate lines when the study runs:

I’ve tried putting in ‘\n’ where the new line should appear, but this didn’t make a difference. Looking at the code there is a ‘\n’ where the new line should be, though for some reason it doesn’t return a new line once the code runs.

Does anyone know why this might happen and if there’s any solution to it?

1 Like

Can you push the “compile script” button on the tool bar, and find the paragraph that starts something like this:

text_1 = visual.TextStim(win=win, name='text',
    text='Your text',

and post it here? Do this without inserting any \n in your text, just use the actual line breaks you type in using the enter key.

Hi Michael,

Here’s what the code looks like:

Text_1 = visual.TextStim(win=win, name='text_1',
    text='    1  -  2  -  3  -  4  -  5  -  6  -  7\n\nNot likely                       Highly likely',
    pos=(0, -0.7), height=0.1, wrapWidth=None, ori=0, 
    color='white', colorSpace='rgb', opacity=1,

This is without me inserting any \n in the text and just inserting two line breaks using the enter key.

OK, I’m mystified by this and can’t replicate it. Are you able to create the smallest possible example Builder file that shows this and post it here? i.e. strip out everything like images, loops etc) and just have a routine that shows only a text stimulus showing this behaviour.

text_test.psyexp (3.5 KB)

I’ve attached an example here with just a single text stimuli where, again, despite there being a \n in the code I get no line break when running the study.

It might be something to do with my computer as I haven’t had this issue previously. I’ll try this on a different machine as well as try to re-install PsychoPy to see if that does anything.

Maybe we’re talking at cross purposes here, as the Builder file you posted has text like this:

text='Not likely  1  -  2  -  3  -  4  -  5  -  6  -  7  Highly likely\n',

i.e. with no line breaks except at the end (which won’t be apparent on screen). But I edited the ext in the text component, putting in some line breaks as required (i.e. just by pushing enter, not by typing \n), and everything appears as intended. So this does seem somehow specific to your system in a way this is not obvious.

Argh! I ran some tests to check different layouts of the text and must have saved the wrong version before posting! Sorry about this.

It should be:

text=u'1  -  2  -  3  -  4  -  5  -  6  -  7  \nNot likely                    Highly likely',

I’ve attached a corrected file now. Sorry againg for that mistake, and thanks for taking the time to help out with this.text_test.psyexp (3.5 KB)

That link is to the same file.


I’m experiencing a similar problem. I’m running v1.90.3 on Mac OSX Sierra. Note that I am also experiencing the issue with the mouse pixel coordinates that seem to double on a retina screen even though this issue was supposed to have been sorted in this version of PsychoPy, so there may be something deeper happening here.

I’m attaching the simplest version of the code. Note that in my case, it is reading text from an excel file, and then it fails to interpret the \n format. When I use carriage returns in the dialog box directly, there is no problem. Attached is the simplest version of the code along with the associated excel file.

InstructionScreens.xlsx (9.5 KB)
CarriageReturn.psyexp (6.4 KB)

The below images show the excel file and the different ways I’ve tried to read that file into PsychoPy

Has this issue been solved yet?

1 Like

I’m running v3.0.0b12 on a Mac 10.13.6 and inserting the ‘\n’ in to the instructions file to add carriage returns did not work for me either. I found a work-around for the issue, though. When I inserted the carriage returns into the text in excel manually (Cmd + Shift + Enter) and saved the instructions file in a ‘.xlsx’ format, they appeared on correctly in the program.

1 Like

Has this been resolved? I am having the same problem with code that worked great with Psychopy 1.90.1. But now that I updated to 3.05, textStim only displays in Arial and does ignores \n and wrapWidth.
I am using a MacOS Mohave, 10.14.3

Thank you,