TypeError: __init__() got an unexpected keyword argument 'alignText'

Hey guys, I am trying to create a Text Stim but it shows this error: TypeError: init() got an unexpected keyword argument ‘alignText’

for pos_i in question_positions:
     current_question = visual.TextStim (win, 
                                          text = '', 
                                          alignText = 'left', 
                                          pos = pos_i, 
                                          height = 25)

How can I fix it?

Hi, it looks like you might have been caught by the current documentation getting ahead of the current release of the software (3.2.4). e.g. at
https://www.psychopy.org/api/visual/textstim.html

it says

alignHoriz
Deprecated in PsychoPy 3.3. Use alignText and anchorHoriz instead

so I’m guessing the alignText parameter won’t be available for use until version 3.3. is released. You could switch to using alignHoriz instead, if it does what you need (it will still work in 3.3, but being deprecated, will possibly be eliminated in the future).

Also, just as a performance tip, you should be wary of creating stimulus objects in a loop, as this is time-expensive (especially for text stimuli). Generally a better way of doing things is to create the object just once, and updates the attributes of that object in the loop, e.g:


current_question = visual.TextStim (win, 
                                    text = '', 
                                    height = 25)

for pos_i in question_positions:
    current_question.pos = pos_i
    current_question.text = some_thing
    current_question.draw()

win.flip()

If you have two lists, one for positions and one for the text content, you can update them together like this:

# get the next position but also a counter index
for i, pos_i in enumerate(question_positions):
    current_question.pos = pos_i
    # update with the corresponding text content:
    current_question.text = some_text_list[i]
    current_question.draw()

win.flip()