我想这样做,以便我向参与者提供1-9之间的数字,并且只有当他们按下该特定数字时,实验才会继续。到目前为止,我有以下代码:
from psychopy import visual, event, core
#draw the blank window
win=visual.Window([1024,768], fullscr=False,allowGUI=True, units='pix',\
color= (0,0,0))
#ready stim
ready = visual.TextStim(win, "Ready", color = (1.0, 1.0, 1.0))
ready.draw()
win.flip()
event.waitKeys()
#create text stimulus
tstim = visual.TextStim(win, text = '', pos=(0, 0))
for number in range(0,10):
# Update text stimulus with the right number
tstim.setText(number)
# Draw the text stimulus
tstim.draw()
# Show on the next refresh
win.flip()
#note to self: figure out how to make it just for the number
event.waitKeys(number)
# Wait 1.0s before continuing
core.wait(1.0)
# Blank the screen by flipping without drawing anything
win.flip()
# Wait for one seconds at the end
core.wait(1.0)
win.close()
当我这样做时,代码不起作用,因为等待键需要是字符串而不是整数。我已经试过了
str(number)
在循环中(在tstim之前),但这不起作用
你能帮我解决这个问题吗,这样我就可以得到它,这样在参与者按下屏幕上当前的数字后,程序就进入下一个数字了
我在这里将代码中的
number
转换为字符串:event.waitKeys(str(number))
而且效果很好
相关问题 更多 >
编程相关推荐