Python/Pygame 导入字体麻烦

Python/Pygame importing fonts trouble

我正在尝试在我尝试构建的游戏中使用一种字体。字体名称是 SansitaOne。 不幸的是 pygame 不允许我导入它。

pygame.font.init()
myfont = pygame.font.Font("incAssests/fonts/SansitaOne.tff",25)

我得到的错误是:IOError:无法读取字体文件名 尽管我已经检查了很多次那是正确的目录。

同样,给我的例子是。

font = pygame.font.Font("myresources/fonts/Papyrus.ttf", 26)

感谢任何帮助。与此同时,我只是在做更有成效的事情。

您可以改用 myfont = pygame.font.SysFont("SansitaOne.tff",25)SysFont 不需要整个 path.But 请确保您的字体是 Windows 字体 directory.Also 您应该写pygame.init()不是那个,font.init是没有必要的。

To install a font

Open Fonts by clicking the Start button Picture of the Start button, clicking Control Panel, clicking Appearance and Personalization, and then clicking Fonts.

Then drag your font to there. That's all.

你应该会看到这个屏幕,把你的字体拖到这里。