Something like this (where images
is a list of 30 pre-created image stimuli):
image_presses = [] # keep track of which images were paused
for trial in trials: # on each trial,
for image in images: # draw 30 images
for frame in range(30): # for 30 frames each (= 500 ms at 60 Hz)
# draw the stimulus:
image.draw()
win.flip()
# check whether to pause
if event.getKeys('space'):
paused = True # stop right here
image_presses.append(frame) # store the current image number
# or could append(image.image) to store the actual image name.
while paused:
if event.getKeys('space'):
paused = False
else:
# need to let the rest of system time to do stuff in this tight loop
time.sleep(0.001) # 1 ms per iteration should do
else:
# when exiting the while loop, also terminate the enclosing 500 ms
# for loop and go on to the next image:
break
Note that as this code is based on drawing frames rather than keeping time, you can be paused indefinitely without issues.