from psychopy import visual,event,core,gui
#creating a window
win = visual.Window(
size=[1080, 720],
units="pix",
fullscr=True,
color=[1, 1, 1]
)
mouse = event.Mouse()#initializing mouse event
#shape on which mouse is to be clicked
rect = visual.Rect(
win=win,
units="pix",
width=200,
height=240,
fillColor=[1, 1, -1],
lineColor=[-1, 1, 1],
pos=(0.0,0.0),
lineWidth=5.0
)
#modified shape upon mouse click
rect1 = visual.Rect(
win=win,
units="pix",
width=200,
height=240,
fillColor=[-1, 1, 1],
lineColor=[-1, 1, 1],
pos=(0.0,0.0),
lineWidth=5.0
)
rect.draw()
win.flip()
while True:
if mouse.isPressedIn(rect): #if shape is clicked rect2 should be drawn
rect1.draw()
win.flip()
print("clicked")
break
else:
event.waitKeys() #if a key is pressed instead of mouse click the program should end
break
On running the code, only the else part runs. The shape cannot be mouse clicked but a key can be pressed.