简体   繁体   English

我的文字不会在pygame中显示

[英]my text won't blit to my display in pygame

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. render()不接受关键字参数,我尝试将True设置为False,但这没有用。 btw what does the middle argument True do? 顺便说一句,中间论点True的作用是什么?

When you see the following error: 当您看到以下错误时:

render() takes no keyword arguments render()不带关键字参数

it means, well, that the render function does not take keyword arguments. 这意味着, render函数不使用关键字参数。

Look at your code: 查看您的代码:

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

You call render with a keyword argument. 您使用关键字参数调用render

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). render需要一个可选的第4个参数(背景色)。 The documentation of pygame wrongly shows it as keyword argument. pygame的文档错误地将其显示为关键字参数。

  • it's better to load your fonts once. 最好一次加载字体。 Currently, you load the font everytime you call the score function 当前,每次调用score功能时都加载字体

  • instead of the font module, consider using the freetype module , which can to everything the font module can, and much more 可以考虑使用freetype模块 ,而不是font模块,它可以使用font模块可以实现的所有功能,以及更多其他功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM