def box_button(x,y, colour, action=None):
toggle = False
pos = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
if click[0] == 1 and (x + 10) + 30 > pos[0] > (x + 10) and (y + 10) + 30 > pos[1] > (y + 10):
if toggle == True:
toggle = False
colour = red
else:
toggle = True
colour = green
pygame.draw.rect(window, white, (x, y, 50, 50))
pygame.draw.rect(window, colour, (x + 10, y+10, 30, 30))
return colour
anyone help this code so it can help me toggle the button from red to green? everytime i click the button with this code all it does it just when i left click, it turns green but when i let go of the click, it goes back to red and i want it to permanentley stay green? thanks