Moving forward and backward through slides in PsychoPy
Moving forward through slides in PsychoPy is super easy, with no code at all. But folks at workshops often asked us “how do we move back and forward through slides like a book?”. Well, this is a great intro to code - so here’s how!
- Make your slides in PowerPoint and ensure they are saved with the naming format Slide1.jpg, Slide2.jpg, Slide3.jpg and so on.
- In PsychoPy add an image component, a keyboard component and a code component to the same routine.
- Add a loop around the routine and set nReps to something big e.g. 500.
- In the image component, set the path to
"pathtoslides/Slide" + str(slideN) + ".jpg"and “set every repeat”
- In the keyboard component only allow the left key, right key and space key.
- In the code component use this in the Begin Experiment tab:
maxSlideN = 5 minSlideN = 1 slideN = 1
this in the End Routine tab:
if key_resp.keys == 'left': slideN -= 1 elif key_resp.keys == 'right': slideN += 1 if slideN > maxSlideN: slideN = maxSlideN if slideN <> minSlideN: slideN = minSlideN
For more tutorials please see the PsychoPy Youtube Channel