Python Pygame得分显示

标签 python pygame display

我正在尝试在 Pygame 的屏幕上显示分数。

这是文本函数。执行时,显示“**AttributeError: 'pygame.Surface' object has no attribute 'get'”* 感谢您的帮助!

   def text(self, surface, text, size, x, y):
          font= pg.font.Font(self.font_name, size)
          text_surface = font.render(text, True, WHITE )
          text_rect= text_surface.get.rect()
          text.rect.midtop = (x,y)
          self.screen.blit(text_surface, text_rect)

最佳答案

您的意思是 text_surface.get_rect(),而不是 text_surface.get.rect()

此外,展望您的函数,您可能指的是 text_rect 而不是 text.rect

关于Python Pygame得分显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49907034/

相关文章:

python - 需要帮助在 PyGame 中使用 for 循环加载图像

python - Pygame 不响应按键

python - 我将如何使用 Pygame 绘制墙壁?

c - 通过管道将图像发送到C中的子进程

actionscript-3 - 在可滚动窗口中显示大量聊天日志或控制台日志的最佳实践是什么? (AS3)

python - Tkinter 图像渲染速度很慢。我应该如何改进呢?

python - tkinter 中不断更新图表

html - display:none 不影响导航栏

python - 使用基于索引的条件对 MultiIndex DataFrame 进行切片

python - 如何停止遍历当前根并迭代到下一个根