【发布时间】:2016-05-07 22:25:27
【问题描述】:
我的函数“hello()”只是在屏幕上显示一个刺激 2 秒,在此期间可以按下一个键。如果没有按下某个键,它会等待 1 秒,然后再次运行该函数,如果没有按下任何键,则一遍又一遍地运行。当一个键被按下时,它退出while循环并打印yes。出于某种原因,如果我让函数循环,例如,在我按下一个键之前循环 4 次,我会同时得到 5 个打印状态,而我只期望一个。有人能告诉我为什么它似乎在存储打印语句,尽管我希望在我按下一个键之前永远不会到达打印语句?
def hello():
test = 1
running = 1
while running == 1:
for frame in range(short_frames): # 2 seconds
fix.draw()
window.flip()
allKeys = event.getKeys(keyList = ('g','h'))
for thisKey in allKeys:
if thisKey == 'g':
keyTime=core.getTime()
test = 2
elif thisKey == 'h':
keyTime=core.getTime()
test = 2
window.flip()
core.wait(1)
if test == 1: #if no key is pressed
hello() #run the function again
running = 2 #exit out of while loop
print "yes"
for i in range(1):
hello()
core.quit()
window.close()
【问题讨论】: