Mouse Click not Registering

I’ve tried reading through almost every thread I can find and still cannot figure out why this basic code doesn’t work. Basically, I am trying to load up an image, create rectangle polygons over them to define a clickable space, and advance the routine on once clicked. however, to know that clicking is working, I’ve been trying to turn the color to red. Here is what I have so far in my trials routine:

Begin Experiment

Mouse = event.Mouse(visible=True,newPos=None,win=Choice_Window)

Begin Routine

Choice_Screen = visual.ImageStim(Choice_Window, image = "Choice_CB.png", pos=[0,0], units = "pix", size = [1280,720])
Choice_Screen.draw()

Left_Rect = visual.Rect(win=Choice_Window, pos=(-260,-40),size=(365,460),opacity=0.5,fillColor=Colour, units = "pix")
Right_Rect = visual.Rect(win=Choice_Window, pos=(260,-40),size=(365,460),opacity=0.5,fillColor=Colour, units = "pix")
Left_Rect.draw()
Right_Rect.draw()

Choice_Window.update()

Each Frame

if Mouse.isPressedIn(Left_Rect):
      Left_Rect.color = 'red'
      Left_Rect.draw()
      Choice_Window.update()

However, when I click on the left rectangle nothing happens. If i then define the mouse click in the builder instead of code, clicking actually causes a crash with the following error:
ValueError: Monitor blank has no known size in pixels (SEE MONITOR CENTER)

Any help appreciated.

1 Like

Hey aarsmith,

have you found a solution for the Value Error? Because I get the same one and I haven’t found any solution on the Discourse Forum so far that helped me to fix it.
If you’ve found a solution, I’d be very grateful if you shared your knowledge with me! :slight_smile:

Hi Pia,

Yes, I did: you need to have a loop going during the each frames code component. For me, this was as simple as asking it to check for a mouse click continuously whenever the clock was greater than 0.

For instance,

While Clock.getTime() > 0: ....

Hope that helps