【发布时间】:2023-03-14 07:27:01
【问题描述】:
当我尝试在我的程序中调用此函数时,如果我运行程序需要很长时间,它将调用错误(在标题中)。在程序上花费超过 5 分钟似乎会导致它崩溃。
Windows 8 蟒蛇 2.7 Psychopy 1.82.02
def WaitForKeyInput():
timer= core.CountdownTimer(5)
trialClock.reset()
text='...'
#until return pressed, listen for letter keys & add to text string
while event.getKeys(keyList=['return'])==[]:
letterlist=event.getKeys(keyList=['0', '1', '2', '3', '4', '5' , '6', '7', '8', '9','backspace','q'])
color = 'black'
if timer.getTime() >= 3:
color = 'green'
elif timer.getTime() >=0:
color = 'yellow'
elif timer.getTime() <0:
color = 'red'
feedback = visual.Rect(mywin, width= 200,height = 200, pos = (0,-100), lineWidth=5.0, lineColor = color)
betAsk.draw()
feedback.draw()
response = visual.TextStim(mywin, height=36,text=text,color="white",pos=(0,-100))
if text != '...':
response.draw()
mywin.flip()
for l in letterlist:
if l == 'q':
core.quit()
#if key isn't backspace, add key pressed to the string
if l !='backspace':
if text =="...":
text=l
pressedkeys=l
else:
text+=l
pressedkeys+=(";" + l)
#otherwise, take the last letter off the string
elif len(text)>0:
text=text[:-1]
pressedkeys+=(";backspace")
event.clearEvents()
【问题讨论】:
标签: python windows python-2.7 psychopy