Visual.TextStim anchorHoriz misbehaving

In the included image, all text strings were drawn at the same X position. There are two blatant things wrong here:

  1. the strings “anchor right” and “anchor left” are both drawn with the x position represented by the red vertical, yet neither string is remotely close to that line.

  2. the strings “anchor right” and “ancRight” should be flush on the right-hand side (ideally flush to the red line), instead they are centered along some imaginary axis.

psychopy.version 2022.1.3

from psychopy import visual, core, event, gui
import psychopy


windowWidth = 1024
windowHeight = 768
winColor = (1,1,1)

win = visual.Window(size = [windowWidth, windowHeight],  fullscr = False, color=winColor, units="pix")

lineTemp = visual.Line(win, (-512, 0),(512, 0), lineWidth = 1.5, lineColor ="red" )
lineTemp.draw()

lineTemp = visual.Line(win, (0, -384),(0, 384), lineWidth = 1.5, lineColor ="red" )
lineTemp.draw()

theText = visual.TextStim(win, "anchorLeft", height = 20, pos = (0,0), color = "black", anchorHoriz = "left"  )
theText.draw()

theText = visual.TextStim(win, "anchorRight", height = 20, pos = (0,0), color = "black", anchorHoriz = "right"  )
theText.draw()

theText = visual.TextStim(win, "ancRight", height = 20, pos = (0,-40), color = "black", anchorHoriz = "right"  )
theText.draw()


theText = visual.TextStim(win, "ancLeft", height = 20, pos = (0,-40), color = "black", anchorHoriz = "left"  )
theText.draw()




win.flip()

So, I finally got it to behave correctly, using a completely undocmented* and non-obvious solution (“hmmm…nothing else works; let’s try this…”). The key is to use both alignText and anchorHoriz. Using just one gives the results as seen in the post above.

lineTemp = visual.Line(win, (0, -384),(0, 384), lineWidth = 1.5, lineColor ="red" )
lineTemp.draw()

theText = visual.TextStim(win, "anchorLeft", height = 20, pos = (0,0), color = "black", alignText = "left", anchorHoriz = "left"  )
theText.draw()

theText = visual.TextStim(win, "anchorRight", height = 20, pos = (0,0), color = "black", alignText = "right", anchorHoriz = "right" )
theText.draw()

theText = visual.TextStim(win, "ancRight", height = 20, pos = (0,-40), color = "black", alignText = "right", anchorHoriz = "right"   )
theText.draw()


theText = visual.TextStim(win, "ancLeft", height = 20, pos = (0,-40), color = "black", alignText = "left",  anchorHoriz = "left"  )
theText.draw()
  • the documentation all but implies that anchorHoriz and alignText should do the same thing.