Exercise 1.13 - using classes with PsychoPy§

Make a “PianoKey” class which contains:

  • A visual.Rect object to represent the key on screen
  • A event.Mouse object to listen to clicks
  • A sound.Sound object to play a sound when pressed

Then add an update method to be called each frame, which:

  • Checks for clicks
  • Plays the sound if clicked
  • Stops the sound when click is released
  • Draws the rectangle

If successful, you should be able to copy and paste your class definition above this code and run it:

Things to keep in mind:

  • What needs to be imported for this to work?
  • What input will the class need in its __init__ function?
  • How will it use these inputs?