Pygame 没有使用指定的字体
Pygame not using specified font
所以我在 pygame 中遇到问题,我指定要使用的字体和大小,但是当我的程序是 运行 时,字体和大小是默认值。
这里是我定义文本的地方
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)
当编辑器 运行 时,"Fatal" 注释下注释掉的行完美运行,但是一旦 运行 作为 .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'
我的电脑上没有安装 freesansbold 字体,但这应该没关系,因为它应该在游戏文件夹中寻找 coure 字体。奇怪的是我说 "Coure" 并且文件名为 "coure.fon",但是当我写那个时,它无法识别。
我想我正在寻找一些关于如何修复错误或如何定义我希望它使用的文本文件的指南。感谢您的帮助!
打开您的 pygame 包文件夹。它应该类似于 C:\Python34\Lib\site-packages\pygame
。应该有一个名为 freesansbold.ttf
的 True Type 字体文件。复制该文件,然后打开包含您的 exe 程序的文件夹。应该有一个名为 library.zip 的压缩文件。打开它并转到压缩文件中的 pygame 文件夹。应该看起来像这样 \build\exe.win32-3.4\library.zip\pygame
。只需将 freesansbold.ttf
文件粘贴到该文件夹中,它就可以正常工作。 freesansbold 字体是 pygame 包中自带的,但是由于某些原因 py2exe
和 cx_Freeze
没有包含它,所以你必须手动添加它。
所以我在 pygame 中遇到问题,我指定要使用的字体和大小,但是当我的程序是 运行 时,字体和大小是默认值。
这里是我定义文本的地方
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)
当编辑器 运行 时,"Fatal" 注释下注释掉的行完美运行,但是一旦 运行 作为 .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'
我的电脑上没有安装 freesansbold 字体,但这应该没关系,因为它应该在游戏文件夹中寻找 coure 字体。奇怪的是我说 "Coure" 并且文件名为 "coure.fon",但是当我写那个时,它无法识别。
我想我正在寻找一些关于如何修复错误或如何定义我希望它使用的文本文件的指南。感谢您的帮助!
打开您的 pygame 包文件夹。它应该类似于 C:\Python34\Lib\site-packages\pygame
。应该有一个名为 freesansbold.ttf
的 True Type 字体文件。复制该文件,然后打开包含您的 exe 程序的文件夹。应该有一个名为 library.zip 的压缩文件。打开它并转到压缩文件中的 pygame 文件夹。应该看起来像这样 \build\exe.win32-3.4\library.zip\pygame
。只需将 freesansbold.ttf
文件粘贴到该文件夹中,它就可以正常工作。 freesansbold 字体是 pygame 包中自带的,但是由于某些原因 py2exe
和 cx_Freeze
没有包含它,所以你必须手动添加它。