module 'pygame' has no attribute 'FONT_CENTER'
时间: 2023-11-19 15:06:21 浏览: 35
根据提供的引用内容,出现了“module 'pygame' has no attribute 'FONT_CENTER'”的错误。这个错误通常是由于拼写错误或者使用了过时的代码导致的。在Pygame中,正确的属性名称是“pygame.font.Font.center”,而不是“pygame.FONT_CENTER”。因此,您需要将代码中的“pygame.FONT_CENTER”更改为“pygame.font.Font.center”。
以下是一个修改后的示例代码:
```python
import pygame
pygame.init()
screen = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Example")
font = pygame.font.Font(None, 36)
text = font.render("Hello, World!", True, (255, 255, 255))
text_rect = text.get_rect()
text_rect.center = screen.get_rect().center
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
screen.fill((0, 0, 0))
screen.blit(text, text_rect)
pygame.display.flip()
```