psychopy.org | Reference | Downloads | Github

Looking for a way to change self.screen.color

I am updating some deprecated code that used to use Pygame to take keyboard inputs “b” and “g”, and since I can no longer use the keyboard input function that was used I was planning on using psychopy. I have written some code but it doesn’t seem to do anything and I was wondering if Im approaching this incorrectly. this is what I have so far:
def Event(self, phase, event):

time.sleep(1)
keys = psychopy.event.waitKeys(keyList=["b", "g"])

if keys != None:
       if 'b' in keys:
	    self.color[:] = [0,1,0]
       if 'g' in keys:
	    self.color[:] = [0,0,1]
       else:
	    pass

It looks like you’re trying to code an experiment by hand but without much Python backgorund. I’d really recommend you start off with Builder.

The code you’re using is trying to change an object called self which you probably don’t have defined anywhere (it’s usually the name used within a class, not in a script).

Create a stimulus (e.g. a Rect) that has size=2, units=‘norm’ and that will fill the screen

background = visual.Rect(win, size=[2,2], units='norm')

if keys:
       if 'b' in keys:
	    background.color = [0,1,0]
       if 'g' in keys:
	    background.color = [0,0,1]
       else:
	    pass