[英]How to get the participant to press a specific number key in python?
I want to make it so that I present participants with numbers from 1-9 and the experiment will only continue if they press that specific number.我想让我向参与者展示 1-9 的数字,只有当他们按下特定数字时,实验才会继续。 So far I have this code:到目前为止,我有这个代码:
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()
When I do this, the code doesn't work as the wait keys needs to be a string not an integer.当我这样做时,代码不起作用,因为等待键需要是字符串而不是整数。 I have tried to do我试过做
str(number)
in the loop (before tstim) but that hasn't worked.在循环中(在 tstim 之前),但这没有用。
Can you help me to solve this so that I can get it so that the program goes onto the next number after the participant has pressed the number that is currently on the screen?你能帮我解决这个问题,这样我就可以得到它,以便在参与者按下当前屏幕上的数字后程序会转到下一个数字吗?
I converted number
to string in your code here:我在您的代码中将number
转换为字符串:
event.waitKeys(str(number))
and it worked fine.它工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.