mouse click on shape object

57 views
Skip to first unread message

m.t....@student.rug.nl

unread,
Jun 5, 2017, 4:45:28 PM6/5/17
to psychopy-users
Hello,

For a couple of hours I try to figure out how write a simple straightforward code which says: In case you click on a given rectangular box shown on the screen, another rectangular box appears on a new screen. If you click on the other rectangular object, another box appears on a new screen.




I came up with the following code which however is insufficient:


import sys
import random
from psychopy import visual,event,core,gui



# definitions

win1 = visual.Window([1370,710], color= 'black', units = 'pix')
timer = core.Clock()
mouse= event.Mouse()


def BOX():
    box2 = visual.Rect(win1,lineColor="black",fillColor="LightGreen",size=[300,150],pos=[0,-160])
    box2.draw()

    box5 = visual.Rect(win1,lineColor="black",fillColor="Blue",size=[300,150],pos=[0,160])
    box5.draw()

    win1.flip()
    mouse



def keys():
    if mouse.isPressedIn(box2):
        box4 = visual.Rect(win1,lineColor="black",fillColor="LightBlue",size=[100,50],pos=[-200,-90])
        box4.draw()
        win1.flip()
       
    
    elif mouse.isPressedIn(box5) :
        box6 = visual.Rect(win1,lineColor="black",fillColor="Pink",size=[100,50],pos=[220,-90])
        box6.draw()
        win1.flip()
        

BOX()

keys()







Any piece of advice would be very much appreciated.

Best,
Marco

Michael MacAskill

unread,
Jun 5, 2017, 6:27:35 PM6/5/17
to <psychopy-users@googlegroups.com>
This forum is deprecated. Please visit http://discourse.psychopy.org



Reply all
Reply to author
Forward
0 new messages