我正在尝试运行python脚本,但是我收到了这个错误。 AttributeError: 'list' object has no attribute 'winType'
:
该文件的实际内容为:
import time
import pylsl
import bci.open_bci_v3 as bci
#from random import random as rand
from pylsl import StreamInfo, StreamOutlet
from psychopy import prefs
prefs.general['audioLib'] = ['pygame']
from psychopy import visual, core, sound
import esys_cfg
NUM_CHANNELS = 8
SAMP_RATE = 100
info = StreamInfo('OpenBCI', 'EEG', NUM_CHANNELS, SAMP_RATE, 'float32', 'myuid34234')
outlet = StreamOutlet(info)
#funtion call to start displaying images
#def displayStimuli
# for file in os.listdir('directory'):
# for i in range(0,len(images)):
# def display(files, .....):
# ex: file_name = ['/dir/dir2/img.png']
window = visual.Window([512, 512])
cfg = esys_cfg.create_config('../stimulus-config/test.yml')
print(cfg.trial_order)
#trial_order = ['one', 'two', 'one']
for element in cfg.trial_order: #loop through all elements in array trial_order
imageIndex = 0
for imageIndex in range(len(cfg.trials[element].files)):
stimulis = cfg.trials[element].stimuli_folder + '/' + cfg.trials[element].files[imageIndex]
showStim = visual.ImageStim(window, stimulis)
showStim.draw([window])
window.flip()
core.wait(2.0)
如何更正并运行程序?
答案 0 :(得分:1)
由于您只能使用一个窗口:
showStim.window = window # stimulus is now drawn to window
showStim.draw()
如果您有多个窗口,则可以将相关窗口作为参数传递(代码中的括号是多余的)。
# Note that this just changes **default** window for stimulus.
showStim.draw(win1)
showStim.draw(win2)
答案 1 :(得分:1)
错误出现在
行中showStim.draw([window])
应阅读
showStim.draw(window)
如果您只有一个窗口,只需执行
showStim.draw()
在窗口中绘制showStim
在初始化时作为参数给出。顺便说一句,初始化心理刺激计算量很大(很容易花费几百毫秒),所以在脚本开始时执行一次,然后在运行时更新相关方面。在你的情况下,这样做:
showStim = visual.ImageStim(window) # initialize the stimulus
for element in cfg.trial_order: #loop through all elements in array trial_order
imageIndex = 0
for imageIndex in range(len(cfg.trials[element].files)):
stimulis = cfg.trials[element].stimuli_folder + '/' + cfg.trials[element].files[imageIndex]
showStim.image = stimulus # update the image