Search code examples
pythonpygamergba

PyGame Error: RGBA Argument


I just started using PyGame and I'm trying to make a message show players when they lose, but I'm getting an error back.

red = (2555, 0, 0)
font = pygame.font.SysFont(None, 25)

def message_to_screen(msg,color):
    screen_text = font.render(msg, True, color)
    gameDisplay.blit(screen_text, [display_width/2, display_height/2])

--etc etc

message_to_screen("You Lose", red)
pygame.display.update()

time.sleep(2)

The exact error message is

 screen_text = font.render(msg, True, color)
 TypeError: Invalid foreground RGBA argument

I can't find any answers online. Please help!


Solution

  • Your problem is with your color definition:

    red = (2555, 0, 0)
    

    The possible values for each RGB channel can be in the range 0 to 256 (exclusive). This means 2555 is waaay to big. Pygame sees this and correctly raises an error. If you're trying to encode the RGB value of the color red, you need to use 255 not 2555:

    red = (255, 0, 0)
    

    As a side note, you may find something like an RGB color selector to be helpful while in the process of choosing colors for your game.