Python program to present an array of pictures and their labels

In a visual world eye-tracking experiment, sometimes the researcher needs to familiarise participants with the pictures they will see before the eye-tracking procedure to allow the participants to associate each picture with a specific label. On this page I share a Python program for this familiarisation task, based on pygame.

What this program does:

The experiment (instructions and trial) can be in any language supported by UTF-8. Just make sure you specify a font that supports that language.

Step 1: Preparation

Step 2: Run the script

Open the Python script in an IDE and pay attention to these variables:

Change the values of those variables to suit your needs. Then, run the Python script.

You should first see a screen that asks you to provide a subject number. This will be the name of your results file as well as the subject number recorded in the data. Start typing and press Enter to confirm and advance.

Then, you should see the instructions. Press Enter to start the task.

In each trial, a random picture along with its label is presented on the screen, with the picture on top, the label below. Press space once the participant is done with looking at it and advance to the next trial.

Once all trials in the list have finished, the program will quit after creating a data file named subject.csv in the designated folder. The data file will record the date and time of trial, the subject number, the trial number, the picture file, the label, and how much time is spent on presenting that picture (rt, in milliseconds).

At any time when the program is running, quit the program by pressing Escape twice in a row. A data file with all presented trials will be created before quitting so don’t worry about losing records.

Back to Top ↑