PyschoPy gives a graphical interface to the programming language Python in order to make it easy for people to generate their own experiments. It can be used to present a subject with a variety of audiovisual stimuli and record their responses to that stimuli.
A simple experiment we can create in PsychoPy is Stroop, which is detailed in this tutorial on YouTube and written below.
Adding Stimuli
When you open PsychoPy two windows will show up the Builder window and the Coder window, we will only be using the Builder window in this tutorial. In the right sidebar of the Builder window, you can select what components you want to add to your experiment. In our case we want to select Stimuli -> Text (the icon with two Ts) which will open a window where you can change various aspects of the text. Note that you can hover over the green plus sign on each icon for a brief explanation of what it does and that you can add other stimuli such as sound or images. We’re going to set the Name of our Text object to “target” and set the start time to 0.5 seconds and the duration of the Text to 4 seconds. For now we don’t need to change anything else about our Text so hit OK and the object should appear on the experiment timeline. You can click the Text icon on the timeline to change its properties in the future.
Adding Response
Over in the component bar we’re going to select Responses -> Keyboard to allow the subject to respond to the text. We’re going to name our Keyboard response and have it start at 0.5 seconds and make the duration blank so that it will accept input infinitely. We’ll also check the Force end of Routine box so that once it receives input, the program moves onto the next stimuli. You can also add responses from the lab microphones or mice.
Adding a Loop
At the bottom of the window there is a Flow bar, under this we’re going to select Insert Loop and move the dot that appears after trial in the flow diagram. We’ll name our loop trials and set its type to be random. We’re going to want to make a conditions file for our loop as well.
Creating Conditions
Conditions files for PsychoPy are made using Excel so you’ll want to make a table that matches this and save it as conditions.xlsx (it must be in the .xlsx file format).
word | color | congruent | corrAns |
red | red | 1 | left |
red | green | 0 | down |
green | green | 1 | down |
green | blue | 0 | right |
blue | blue | 1 | right |
blue | red | 0 | left |
You cannot have any spaces in your column names or data in PsychoPy and it will give you a warning if you try to use a file that does. We’ll want to go back into the loop from earlier and browse for the conditions.xlsx file. We’ll also want to set nReps $ to 1 so that it only goes through all the conditions in the file once.
Using Conditions
Now that you have imported a conditions file your going to want to go back into your Text object target and set the Color equal to $color and the Text to $word. The dollar sign signifies that this value is a variable so PsychoPy knows to go into the conditions file to get a value to replace it. You should go back into the Keyboard response and set the Allowed keys $ to be ‘left’, ‘right’, ‘down’ and the Correct answer to $corrAns and make sure that Store correct is checked off.
Making New Routines
We probably want to give the subjects some form of instruction for taking the test so we’ll do this by adding a new routine to the experiment. Down in the Flow bar click Insert Routine -> (new) and name the new routine instructions. You’ll then want to move the dot that appears to the left of our trials loop (make sure it’s outside the loop, we don’t want it to appear every time a new word is going to be shown). Then you want to create a new Text stimuli that starts and zero and has an infinite duration (leave duration blank) and have the text say
Remember, choose the color of the
letters, ignoring the wordleft = red
down = green
right = blue
You’ll also want to create a new Keyboard that starts at zero and goes on until a key is pressed (leave duration blank and check Force end of Routine). You’ll also want to leave Allowed keys $ blank so that it accepts any input and Store nothing since the input for this screen is not part of the experiment.
Running your Experiment
First you’ll want to save your experiment using the floppy disk icon at the top of the window, I recommend creating a new folder for the experiment since the data will be saved to the same location. Then select the green icon with the runner on it to run your program. It will prompt you for a participant name and a session, and when you hit OK the experiment will run. After you finish the experiment, the data will be stored in a data folder where your experiment is save. Each subject will have a .csv, .log, .psydat, and .xlsx saved in the format of SubjectName_ExperimentName_Year_Month_Day_24HourTime and contain information such as response time and the correctness of their answers.