noobprogrammer
noobprogrammer

Reputation: 153

TypeError: Invalid foreground RGBA argument

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))

Upvotes: 4

Views: 1616

Answers (2)

Rabbid76
Rabbid76

Reputation: 210890

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))

Upvotes: 0

Taek
Taek

Reputation: 1024

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))

Upvotes: 6

Related Questions