0

i am trying to make a score in the top left corner of my screen but it is returning an error.

i have searched it up online and followed the exact steps but still it returns an error.

def score(rounds):
    font = pygame.font.SysFont(None, 25)
    text = font.render(f'ROUND {rounds}', True, size=25)
    game_display.blit(text, (0,0))

render() takes no keyword arguments i have tried putting the True in as False but that didn't work. btw what does the middle argument True do?

BOBTHEBUILDER
  • 345
  • 1
  • 4
  • 20

1 Answers1

3

When you see the following error:

render() takes no keyword arguments

it means, well, that the render function does not take keyword arguments.

Look at your code:

text = font.render(f'ROUND {rounds}', True, size=25)

You call render with a keyword argument.

Just don't do it. Don't use a keyword argument. It's as simple as that.

Also, the third parameter has to be a color-like object, so your code should look like this:

text = font.render(f'ROUND {rounds}', True, pygame.Color('orange'))

Some more notes:

  • render takes an optional 4th argument (a background color). The documentation of pygame wrongly shows it as keyword argument.

  • it's better to load your fonts once. Currently, you load the font everytime you call the score function

  • instead of the font module, consider using the freetype module, which can to everything the font module can, and much more

sloth
  • 99,095
  • 21
  • 171
  • 219
  • thanks but now it says invalid foreground RGBA argument – BOBTHEBUILDER Jan 11 '19 at 08:35
  • @BOBTHEBUILDER What are you passing as parameter? It has to be a valid tuple describing a colour, like `(200, 0, 100)`, or a `pygame.Color` instance – sloth Jan 11 '19 at 09:38
  • The questioner probably doesn't know what a keyword argument is. Replace "size=25" with just 25. – Benice Apr 27 '21 at 02:48