psychopy.org | Reference | Downloads | Github

Same (simple) GratingStim code won't display after 2nd run (WinOS)

Hi,

I recently installed PsychoPy and was able to make it work on Windows under Spyder. I tested it with a simple GratingStim code (see below the simple code).

However, while the first time the grating stimulus appears correclty, the second time i run the same code the window opens but no grating display appears.

Does anyone have any idea of what is going on?

Thanks
Gian luca

import sys
sys.path.append("C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.84.2-py2.7.egg")
sys.path.append("C:\Program Files (x86)\PsychoPy2\Lib\site-packages")
 # NOTE: I had to include the code above otherwise Spyder would not recognize the PsychoPy module

import psychopy.visual
import psychopy.event

win = psychopy.visual.Window(
    size=[400, 400],
    units="pix",
    fullscr=False
)

grating = psychopy.visual.GratingStim(
    win=win,
    units="pix",
    size=[150, 150]
)

grating.draw()

win.flip()

psychopy.event.waitKeys()

win.close()

Have you tried running the script outside of the Spyder environment (i.e. directly from the command line)?

I assume you’re currently executing the script by pressing F5? Could you try running and re-running in a new interpreter instead (via F6), or execute the IPython magic %reset before the second run?

%reset worked! Thanks a lot!