I’m trying to control the position of an image stimuli for my experiment on PyCharm.
The stimulus window appears only for a second and then disappears, and it does not take any keyboard input.
Does working with PsychoPy on PyCharm need any specific arrangements?
This is my code:
from psychopy import core, event, visual, monitors, clock
import psychopy.event
# monitor
widthPix = 1920 # screen width in px
heightPix = 1080 # screen height in px
monitorwidth = 53.1 # monitor width in cm
viewdist = 60. # viewing distance in cm
monitorname = 'monitorname'
Screen = 0 # 0 to use main screen, 1 to use external screen
mon = monitors.Monitor(monitorname, width=monitorwidth, distance=viewdist)
mon.setSizePix((widthPix, heightPix))
mon.save()
# Initialize window
win = visual.Window(
monitor=mon,
size=(400, 400),
units='pix',
screen=Screen,
allowGUI=True,
fullscr=False)
period = psychopy.core.StaticPeriod(screenHz=60)
image = 'C:/Users/CVBE/PycharmProjects/spaceship_in_psychopy/spaceship.png'
image_stim = visual.ImageStim(win, image, pos=(0.0, 0.0))
image_stim.draw()
# text_stim.draw()
win.flip()
# period.complete()
keys = psychopy.event.waitKeys()
text_stim = visual.TextStim(
win,
text=keys,
pos=(0.0, 0.0),
units="norm",
height=0.05,
wrapWidth=0.8,
)
# period.start(2)
# image_stim.draw()
text_stim.draw()
if keys == 'right':
print(keys)
image_stim = visual.ImageStim(win, image, pos=(50, 0.0))
text_stim.draw()
image_stim.draw()
win.flip()
period.complete()
win.close()
elif keys == 'left':
print(keys)
image_stim = visual.ImageStim(win, image, pos=(-1.0, 0.0))
image_stim.draw()
win.flip()
elif keys == 'up':
print(keys)
image_stim = visual.ImageStim(win, image, pos=(0.0, 1.0))
image_stim.draw()
win.flip()
elif keys == 'down':
print(keys)
image_stim = visual.ImageStim(win, image, pos=(0.0, -1.0))
image_stim.draw()
win.flip()
else:
image_stim = visual.ImageStim(win, image, pos=(0.0, 0.0))
image_stim.draw()
win.flip()