Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
运行程序时出现此错误:
OSError: 无法读取字体文件 'C:\Users\Büşra\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pygame\freesansbold.ttf'
我是pygame的初学者。我的代码是这样的:
mainfont=pygame.font.Font("freesansbold.ttf",18)
我在想这部分目录:C:\Users\Büşra是问题所在。
C:\Users\Büşra
Python 和其他编程语言及其库对 unicode 文本反应不佳,很可能导致错误。
我建议将字体文件 [.fon或.ttf] 放在与游戏或脚本相同的目录中,并像这样引用它:
.fon
.ttf
example = pygame.font.Font('./myfont.ttf', size)
那应该行得通。