Windows 10 Python 3.7 水蟒1.9.7 间谍3.3.3 适用于Python 2.7的PsychoPy
我正在编码一个实验,该实验需要以随机顺序呈现图像以使参与者响应。我能够以数组的形式获取图像,但是每次使用一次循环时都会显示一个图像,每次循环都会使变量增加1。它无法将变量识别为数字,因此数组无法调用任何东西。
我尝试不随机化变量以查看是否是问题所在,但似乎只是我的变量i没有被读为数字
#import packages
import random, os
from psychopy import core, visual, event
from PIL import Image
#setup screen with specs and draw
win = visual.Window([400, 300], monitor="testMonitor")
message = visual.TextStim(win, text="")
message.draw()
win.flip()
core.wait(3.0)
#set image size and populate array with images
stim_size = (0.8, 0.8)
image = [i for i in os.listdir('C:/Users/*/psychopy-tests')
if i.endswith('.bmp')]
#randomize image order
images = random.shuffle(image)
i = 0
while i != 29: #there are only 28 images
new = images[i] #this is where the issue is
image_stim = Image.open(new)
stim = visual.ImageStim(win, image_stim, size = (stim_size))
stim.draw()
win.update()
output = []
if event.getKeys(keyList=['space']):
output[i] = 1
if event.getKeys(['escape']):
win.close()
core.quit()
if event.getKeys(keyList=None):
output[i] = 0
core.wait(5.0)
i = i + 1