psychopy.org | Reference | Downloads | Github

Signalling response after mouse click

#1

Hi,

I have five images appearing on the screen and I want to signal to the participant which one they have clicked.
The participant will select one image via mouse click and I want the one they choose (regardless of whether or not it is the correct choice) to have a border surrounding it

I have polygons behind each of the images that participants can click.

I want the colour of the polygon to change from grey to (some other colour) whenever a participant clicks on an image. I also want the colour to change back to grey after participants press the image because participants can click on multiple images in a trial. So I want the border to change to a different colour for every mouse click that participants make on an image.

My current code is:
if mouse.isPressedIn (PRightOne): PolygonColor = 'white' in BeginRoutine

and added this as the fill color for the polygon image

I am getting an error saying that PolygonColor is not defined as well as other errors.

Let me know how I can solve this problem,
Thanks!

#2

That error is easy to fix but we should really deal with all of them, so please provide full details.

#3

This is the error I’m getting
image

#4

But you also said:

Is this in fact the only error to deal with?

#5

Yes, this is the only one coming up right now

#6

OK. How about:

  • just set the colour of each polygon to be constant, with an initial value of grey.
  • Then we can handle the colour changing entirely in code, in the “each frame” tab of a code component (make sure the code component is above the other stimuli, so that they respond immediately to any changes, rather than waiting for the next frame).
polygons = [polygon_RightOne, polygon_PWrong1, polygon_PWrong2, polygon_PWrong3, polygon_PWrong4]
images = [PRightOne, PWrong1, PWrong2, PWrong3, PWrong4]

# check for a mouse click in each image stimulus. If detected, change
# the colour of its corresponding polygon:
for i, image in enumerate(images):
    if mouse.isPressedIn(image):
        polygons[i].color = 'white'
    else:
        polygons[i].color = 'grey'