psychopy.org | Reference | Downloads | Github

Text alignment of a block of text, not left-aligned

I have this code for inputting my text:

A1Info = visual.TextStim(win=win, name='A1Info',
    text='Text text text text. \n\nMore text text text. etc.', #this is several lines of text or 'text-block
    font='Arial',
    pos(0,0), height=0.06, alignHoriz='center', wrapWidth=1.6, ori=0, 
    color=[-1.000,-1.000,-1.000], colorSpace='rgb', opacity=1, 
    languageStyle='LTR',
    depth=0.0)

The text always shows up as left-aligned. I’m trying to present text as centre-aligned on the screen. If I understand correctly, pos(0,0) tells the code that the middle position of the screen is 0,0. The ‘alignHoriz’ command left aligns the text-block to the left or right or in the centre of pos(0,0) but always with left alignment. Is there code to centre-align a block of text so that the centre of each line of text is in the middle of the screen or do I have to do each line separately?

1 Like

Have you found a way? I’d like to do the same!

Currently the text stimulus doesn’t quite operate in the way that you might (naturally) expect, as per discussion here:

A new and improved text stimulus is on the way but unfortunately if you need this functionality right now, you are probably going to need to manually pad your text with spaces to achieve what you want.

1 Like

I’d like to do the same thing with a picture does anyone knows how?

Hi, images are automatically centre-aligned, because when we set their positions, that position refers to the centre of the image, nor matter what its dimensions are. e.g. if you have two images at position [0, 0.5] and [0, -0.5] in normalised coordinates, they will appear horizontally centred along the vertical midline of the screen. If they are at [-0.5, 0] and [0.5, 0] they are vertically aligned along their centres, along the horizontal midline of the screen.

https://www.psychopy.org/general/units.html

Thanks Michael,

I was able to achieve it by setting the position of the image as follows:
targetImage.pos = [x,y] where x and y are the x and y coordinates of the image respectively with negative values on the left leaning to negative values in the x coordinate and negative values on the right leaning to negative values on the y coordinate.