psychopy.org | Reference | Downloads | Github

Mouse click on image to indicate choice

To simplify my question, I want the subjects to click on one of the two given images to indicate a choice. I defined two visual stimuli, display them, and the response is registered by mouse click on one of the stimuli.

image1 = visual.ImageStim(win = mywin, name = “image1”, image = “tropical3.jpg”, color = (1,1,1), size = [11,11], pos = (-15,4))
image2 = visual.ImageStim(win = mywin, image = “tropical4.jpg”, color = (1,1,1), size = [11,11],pos = (0,4))

image1.draw()
image2.draw()

if event.Mouse.isPressedIn(image1):
print (“yes”)

The error message is “TypeError: isPressedIn() missing 1 required positional argument: ‘shape’”. Would really appreciate any help on this. Thanks so much!

Hi, it seemed like you didn’t call flip() yet (in your case, mywin.flip()) after preparing the images.
My guess is that the images did not show on the screen and caused the error. Could you add mywin.flip() after drawing the stimuli to see it that fixes the problem?

Thanks for your quick response! I tried but I am still getting the same error message.

I cannot reproduce the error with the below snippet. Could you copy and paste the codes you used?

from psychopy import visual
from psychopy import event

# create a Window
win = visual.Window(size=(1920, 1080), units='pix', fullscr=True)
my_mouse = event.Mouse()
# draw a image
ok = visual.ImageStim(win, image='ok.png')
ok.draw()
win.flip()

while True:
    if my_mouse.isPressedIn(ok):
        break

Hi, I’m trying to do something similar to this. But I need an else condition in the while loop, so that user could have an option of not selecting the image and simply leave the screen, using the event.waitKeys() function. However, on doing this, it stops taking input from the mouse and takes the else condition into consideration(takes a key press). Any idea about this?