pygame的字体画不出来_Pygame不使用指定的字体

So I am having a problem in pygame where I specify the font and size to use, but when my program is run, the font and size are the default.

Here is where I define the text

def font(self):

'''*****FATAL - THIS LINE CAUSES ERROR (When compiled to .exe using cx_freeze)*****'''

#font = pygame.font.SysFont("Coure", 20)

font_color = (0, 0, 0)

font = pygame.font.Font("coure.fon", 20)

self.text = font.render("Level "+str(self.level) + " " + self.name + " Health " + str(self.health), True, font_color)

The line commented out under the "Fatal" comment works perfectly when run from the editor, however causes this error once it is run as an .exe

Fatal Python error: (pygame parachute) Segmentation Fault

Traceback (most recent call last):

File "C:\Python34\lib\site-packages\pygame\pkgdata.py", line 67, in getResource

return open(os.path.normpath(path), 'rb')

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Jared\\Desktop\\Python\\Boss Battle\\build\\exe.win32-3.4\\library.zip\\pygame\\freesansbold.ttf'

I don't have the freesansbold font installed on my computer, but that shouldn't matter, since it should be looking for the coure font in the folder of the game. The weird thing is that I say "Coure" and the file is named "coure.fon", but when I write that, it is unrecognized.

I guess Im looking for some guidence on how to fix either the error, or how to define which text file I want it to use. Thanks for any help!

解决方案

Open up your pygame package folder. It should be something like C:\Python34\Lib\site-packages\pygame. There should be a True Type Font File titled freesansbold.ttf. Copy that file then open the folder containing your exe program. There should be a zipped file called library. Open it up and go to the pygame folder inside the zipped file. Should look something like this \build\exe.win32-3.4\library.zip\pygame. And just paste the freesansbold.ttf file in that folder and it should work perfectly. The freesansbold font comes with the pygame package, but for some reason py2exe and cx_Freeze don't include it, so you have to add it manually.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值