4
votes

Every time I try to run the Pygame program, I get this error:

TypeError: Invalid foreground RGBA argument

Here is my code, do you have any idea why ?

text = font.render(b’Score:’ , dude.score, 1, (0, 0, 0))
2
I'm not sure it'll fix it, but (0,0,0) is RGB, (0,0,0,1) is RGBA. - Michael Bianconi
@MichaelBianconi It didn’t. Thanks for trying though. - noobprogrammer

2 Answers

6
votes

as per the docs Font.render takes rgb as his third argument, you pass it as fourth. This does not raise a proper error because font.render takes a fourth optional argument background.

Try text = font.render('Score:'+str(dude.score), 1, (0, 0, 0))

0
votes

The first 3 parameters of pygame.font.Font.render are position-only parameters. Positional-Only Parameters. The text, antialiasing and the color. Therefore, you can just pass a single string to the rendering function.

Use a formatted string literal

text = font.render(f'Score: {dude.score}', 1, (0, 0, 0))

or use the 'str()' function to convert the number to a string and concatenate the strings

text = font.render('Score: ' + str(dude.score), 1, (0, 0, 0))