gpt4 book ai didi

python - 从 pygame 中的文件位置 ptext 指定字体

转载 作者:行者123 更新时间:2023-12-01 07:01:59 25 4
gpt4 key购买 nike

我了解如何在普通 python 中使用 .ttf 文件中的字体。

font1 = pygame.font.Font("/resources/fonts/robotoThin.ttf")

但是我在ptext的文档中找不到,或者在网络上如何在使用时指定字体

ptext.draw(text,(x,y))

使用pycharm

最佳答案

根据ptext repo's README ,您可以在调用 ptext.draw 时指定 fontname 参数,如下所示:

ptext.draw(text, (x,y), fontname="fonts/Viga.ttf")

还有用于为字体名称创建模板的选项(请参阅上面的链接),但我没有找到将字体保存为变量以避免每次重新加载的方法。

关于python - 从 pygame 中的文件位置 ptext 指定字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58593502/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com