I want to change the color of a button if the user presses on it to and from the original color.
Let’s say the original color is ‘darkgray’.
If the user presses on it once, it turns in ‘blue’.
If the user presses on it again, it turns from ‘blue’ to ‘darkgray’ again and so on and so forth.
I select colors in this format and not RGB (e.g. [0,0,0]) because I think it will be easier to convert to JS for the online one.
I wrote the below code so far, but it only works for the first click (turning the color from darkgray to blue, but not from blue back to darkgray again):
clickedN=0 for clickable in clickables: if mouseButton.isPressedIn(clickable): clickable.fillColor = 'blue' clickedN += 1 elif mouseButton.isPressedIn(clickable) and clickable.fillColor == 'blue': clickable.fillColor == 'darkgray' clickedN += 1 if clickedN==1: continueRoutine == True
I also found the following resource here:
I hence tried adapting my code as such:
if mouseButton.getPressed() == 0: fills = [polygonButtonYES.fillColor, polygonButtonNO.fillColor] for clickable, index in enumerate([polygonButtonYES, polygonButtonNO]) # If mouse pressed in square, match current square to square stored in fills list # Check if the colour has not changed. If it has not changed, change the colour of the square # that contains the mouse click if mouseButton.isPressedIn(clickable) and fills[index] == 'darkgrey': clickable.fillColor = 'blue' elif mouseButton.isPressedIn(clickable) and fills[index] == 'blue': clickable.fillColor = 'darkgrey'
But I receive this error:
Alert 4205:Python Syntax Error in 'Each Frame' tab. See 'for clickable, index in enumerate([polygonButtonYES, polygonButtonNO]) ' on line number 7 of the 'Each Frame' tab.
Any ideas on how to solve this?
Can this be done using the buttonStim directly and not using “Polygon + Mouse” ?