Hi guys,
I’m looking to add a constant background (a frame around the stims) to every trial of an experiment and to the instructions. It’d be a pain to add the image to each routine with visual.ImageStim(), so I’m wondering if there’s a quick way to specify a background when setting up the window instead?
Thanks!
This sounds like Builder but you put it in the Code category. So I’m answering for both
You cannot set a background picture in the window object itself. But you could use the autoDraw
property of many stimuli to always draw it. So:
background_image = visual.ImageStim(win, 'my_folder/my_image.png', autoDraw=True)
If this is Builder, do it in a Code component which runs on “Begin Experiment”. If you want to turn it on or off some time during your experiment, just do:
background_image.autoDraw = False # Turns off
background_image.autoDraw = True # Turns on (again)
Ah that’s exactly what I was after; thanks for the quick reply!
Hi @TZK ,
Can you share more info?
Did follow the above guidelines but got this error:
Traceback (most recent call last):
File “\PsychoPy\TestExperiment1\TestExperiment1rev2_lastrun.py”, line 31, in
background_image = visual.ImageStim(win, ‘novel191.bmp’, autoDraw=True)
NameError: name ‘win’ is not defined
Any clues how to move on?
Hi @Sharon.Psy,
To be honest, I didn’t remember which experiment my original question was in reference to, but I did find one on my computer from four years ago where I successfully added a white boarder around the stimuli. In case it helps, here’s how it looked, which seems to be a combo of both of the above suggestions. I used builder in PsychoPy2 and inserted a code component which had this under the “begin experiment” tab:
background_image = visual.ImageStim(win, 'Frame.png')
Where “Frame.png” was in the same directory as the .psyexp file.
Then I turned it on or off with a separate code chunk in each routine by adding this under the “begin routine” tab:
background_image.autoDraw = True
background_image.autoDraw = False