Windows 10 Python 3.7 Anaconda 1.9.7 Spyder 3.3.3 PsychoPy for Python 2.7
我正在编写一个实验,需要以随机顺序呈现图像以供参与者响应。我能够在一个数组中获取图像,但是为了一次呈现它们,我使用的是一个while循环,每次循环时变量都会增加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