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!

Overview

  1. Make your slides in PowerPoint and ensure they are saved with the naming format Slide1.jpg, Slide2.jpg, Slide3.jpg and so on.
  2. In PsychoPy add an image component, a keyboard component and a code component to the same routine.
  3. Add a loop around the routine and set nReps to something big e.g. 500.
  4. In the image component, set the path to "pathtoslides/Slide" + str(slideN) + ".jpg" and “set every repeat”
  5. In the keyboard component only allow the left key, right key and space key.
  6. 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

Dr. Rebecca J. Hirst
Dr. Rebecca J. Hirst
Cognitive Scientist

My research interests include multisensory perception and experimental design.