Skip to main content
 首页 » 编程设计

python之尝试在 macOS Sierra 上显示文本时 Pygame 没有响应

2025年02月15日8powertoolsteam

我已经按照 programarcadegames.com 上的说明在 python 3.5.3 上安装了 pygame 版本 1.9.4。 .当我使用 pygame 绘制线条和形状时,它很好,但是当我尝试使用 pygame.font.SysFont 时,pygame 不再响应。例如,当我运行以下代码时,将显示一个无响应的 pygame 窗口:

 
import pygame 
 
pygame.init() 
 
BLACK = (0, 0, 0) 
WHITE = (255, 255, 255) 
 
size = (400, 500) 
screen = pygame.display.set_mode(size) 
 
done = False 
clock = pygame.time.Clock() 
 
while not done: 
 
    for event in pygame.event.get():  # User did something 
        if event.type == pygame.QUIT:  # If user clicked close 
            done = True  # Flag that we are done so we exit this loop 
 
    screen.fill(WHITE) 
 
    font = pygame.font.SysFont(None, 25, True, False) 
 
    text = font.render("Some Text", True, BLACK) 
    screen.blit(text, [0, 0]) 
 
    pygame.display.flip() 
    clock.tick(60) 
 
pygame.quit() 
 

请您参考如下方法:

将 font = pygame.font.SysFont(None, 25, True, False) 替换为 font = pygame.font.Font(None, 25) 解决了这个问题, 但目前还不清楚是什么原因造成的。