Setting autoDraw on TextStim

Hi everyone,

I’m new to PsychoPy, and I’m running into a problem when drawing stimuli on the screen. Right now, I have several stimuli up on the screen at once, and I want a blue border to appear around one of these stimuli when the participant selects it with a keypress. The following code triggers when the participant selects a stimulus:

    myShapeStim.setLineWidth(30)
    myShapeStim.setLineColor('#48d1cc')
    win.flip(clearBuffer=False)

Of course, this by itself draws a border around that one ShapeStim and causes everything else on the screen (including alternative stimuli, text prompts, etc.) to disappear.

I’ve tried to fix this by setting autoDraw=True on each of the stimuli on the page. This works fine for ShapeStim, but when I try to set autoDraw=True on TextStim, I get this error:

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

This is confusing, because the documentation for TextStim clearly states that I should be able to set autoDraw as an option:

autoDraw
Determines whether the stimulus should be automatically drawn on every frame flip.
Value should be: True or False. You do NOT need to set this on every frame flip!

So, my questions are:

  • Why isn’t autoDraw working for TextStim?
  • Is there another, more compact way of keeping the screen from clearing when a border is drawn around one of the stimuli?

Thanks for your help!

Best,
Natalia

What it states is that it can be set after a text object is created. (i.e. notice that autoDraw isn’t one of the parameters listed when as a parameter for when the object is instantiated (which does seem to be inconsistent with some other visual stimuli)):

class psychopy.visual.TextStim(win, text=‘Hello World’, font=‘’, pos=(0.0, 0.0), depth=0, rgb=None, color=(1.0, 1.0, 1.0), colorSpace=‘rgb’, opacity=1.0, contrast=1.0, units=‘’, ori=0.0, height=None, antialias=True, bold=False, italic=False, alignHoriz=‘center’, alignVert=‘center’, fontFiles=(), wrapWidth=None, flipHoriz=False, flipVert=False, name=None, autoLog=None)

But once a text stimulus is created, you should be able to do this:

myText.setAutoDraw(True) 

or

myText.autoDraw = True

Also, a better approach here is have a single win.flip() for all of your stimuli rather than have several conditional win.flip() lines. What should be conditional is whether a given stimulus is set to be drawn, or to be invisible, on the next win.flip() . e.g. just do something like this:

if some_key_has_been_pressed():
    myShapeStim.autoDraw = True
else:
    myShapeStim.autoDraw = False

or

if some_key_has_been_pressed():
    myShapeStim.opacity = 1
else:
    myShapeStim.opacity = 0

And then only ever have one win.flip() statement. That makes it much easier to know what is appearing and when.

2 Likes

A lot of good advice here—thank you so much for your help! It works now; I’ve also placed win.flip outside of the conditional, s.t. only setLineWidth and setLineColor are conditioned on the keypress. I agree that it’s much easier to control what I’m showing this way.