This repository contains a collection of useful PsychoPy scripts for designing and implementing psychophysical tests in human research. These scripts cover various aspects of test design, including interactive elements, response collection, and data handling.
PsychoPy is a powerful tool for creating experiments in Python, and this repository provides example codes to assist in the development of psychophysical tests. The provided scripts can be used to create interactive stimuli, collect participant responses, and analyze psychophysical data.
slider_bar_psychopy.py: Example script for creating an interactive slider bar where users can adjust a value by dragging the slider handle.example_2.py: (Add other example scripts here with brief descriptions)example_3.py: (Add other example scripts here with brief descriptions)
- Python: Ensure you have Python installed.
- PsychoPy: Download and install PsychoPy. For installation instructions, visit PsychoPy Installation.
-
Install PsychoPy: Install PsychoPy via pip if you haven’t already:
pip install psychopy
-
Run the Script:
-
Save the script you want to use (e.g.,
slider_bar_psychopy.py) to your local machine. -
Navigate to the directory containing the script.
-
Run the script using Python:
python slider_bar_psychopy.py
-
-
Interact with the Test Elements:
- Follow the instructions provided in the script to interact with the test elements.
- For the slider bar example, click and drag the slider handle to adjust the value.
- Press 'q' to quit the experiment.
The slider_bar_psychopy.py script demonstrates how to create an interactive slider bar using PsychoPy. The slider responds to mouse input, allowing users to adjust a value by dragging the handle.
- Initialize PsychoPy: Opens a PsychoPy window.
- Create the Slider: Uses
visual.Sliderto create an interactive slider. - Instructions: Displays instructions using
visual.TextStim. - Main Loop:
- Draws the slider and updates its value based on mouse position.
- Checks for the 'q' key to exit the loop.
- Get the Slider Value: Prints the current slider value.
- Cleanup: Closes the window and exits.
Here’s the full code for the slider bar example:
from psychopy import visual, core, event, gui
win = visual.Window([800, 600], color=[1, 1, 1], units='pix')
slider = visual.Slider(win, ticks=(0, 1), labels=['0', '1'], size=(400, 20), pos=(0, 0), style='rating', color='black', fillColor='red')
instructions = visual.TextStim(win, text='Drag the slider to adjust the value.\nPress "q" to quit.', pos=(0, 250), color='black')
running = True while running: instructions.draw() slider.draw() win.flip()
# Check for mouse clicks
mouse = event.Mouse()
if mouse.isPressedIn(slider):
slider.setRating(mouse.getPos()[0] / slider.size[0])
# Check for exit condition
keys = event.getKeys()
if 'q' in keys:
running = False
slider_value = slider.getRating() print(f'Slider Value: {slider_value}')
win.close() core.quit()
Contributions are welcome! If you have additional PsychoPy scripts or improvements, please fork the repository, make changes, and submit a pull request. For significant changes, open an issue to discuss your proposed modifications.
This project is licensed under the MIT License - see the LICENSE file for details.