← Other topics

PsychoPy - Easy Introduction (#1)

Series contents:

Video Notes

Quick jump to the lexical decision task examples


This is the first video in a series I’ll be doing that covers building experiments using PsychoPy.

PsychoPy is an open-source software package written in Python that is used for creating and running experiments in psychology, neuroscience, and related fields. It provides a powerful and flexible environment for designing a wide range of experiments, including behavioral studies, neuroimaging experiments, and cognitive tasks.

In this first video, I give a broad overview of getting PsychoPy installed and then explain the difference between the two main modes of designing experiments:

  1. Using the Coder View where you write the entire experiment in Python code
  2. Using the Builder View where you build an experiment using a visual interface
PsyhoPy Coder View and Builder view

As an example, I show a basic lexical decision task experiment.

In subsequent videos, I will go into more detail of building this experiment using both the Coder view and Builder view. This page will be updated with links when those videos are updated. If you want to be notified when those videos are published you can subscribe to my YouTube channel.

Key points discussed in this video

  • Code experiments have a .py extension and are run via the Coder view
  • Builder experiments have a .psyexp extension and are run via the Builder view
  • Each view has a green play button to run the experiments
  • The Runner view shows you details about any currently running experiments and includes a stop button to terminate an experiment
  • When working in the Builder the main ingredients of an experiment include the Flow, Routines, and Components.
    • The Flow is the timeline of the experiment and it consists of Routines which are made up of Components.
    • Example Components include things like text elements, images, or keyboard/mouse listeners to collect responses from the participant.

Builder example

Click here to download the lexical decision task zip...

Coder example

Example code for a lexical decision task experiment:

# Import the modules we’ll need
from psychopy import core, visual, event
import random

# Initialize an empty string that will accumulate our results of each trial
results = ''

# Define our conditions
conditions = [
    ['cat', 1],
    ['tea', 1],
    ['bar', 1],

# Randomize the conditions

# Define the window
window = visual.Window(size=(800, 700), color='black')

# Define the instructions
welcome = '''
Welcome to the lexical decision task.

You are about to see a series of characters. 

If the characters make up a word, 
press the RIGHT arrow key.

If the characters do not make up a word, 
press the LEFT arrow key.

Press SPACE to begin.

instructions = visual.TextStim(window, color='white', text=welcome, units='pix', height=20)

# Display the instructions and wait for the space bar to be hit to start

# Begin trials
for condition in conditions:
    characters = condition[0] 
    isWord = condition[1] 

    # Define the stimulus (word text)
    word = visual.TextStim(window, color='white', text=characters, units='pix', height=40)
    # Display the stimulus

    # Listen for a left or right key response
    response = event.waitKeys(keyList=['right', 'left'])
    # Check response accuracy
    if(isWord == 1 and response[0] == 'right'):
        correct = 1
    elif(isWord == 0 and response[0] == 'left'):
        correct = 1
        correct = 0
    # Append the results as an CSV string
    results += characters + ',' + str(isWord) + ',' + str(correct) + '\n'

# Output the results to the console

# The next two lines ensure the PsychoPy application is properly terminated. 
# If you omit these lines, the window will still close when the script is done, but these
# lines that system resources associated with the window are released properly.

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics