编辑:
所以这是使用pygame.font.SysFont() 的问题。我不确定为什么它不起作用,而且很难找到,因为它使用 .pyd 文件,我相信这是 c API 的扩展。解决此问题的方法是改用pygame.font.Font()。在您的应用程序中,您发送 None 作为字体,它只返回 pygame 的默认字体,即 freesansbold.ttf。要使用此字体,您需要将其包含在包中,因为它在 Windows 注册表中不存在。
import os # Importing os and pygame at top of spec sheet
import pygame
pygame_dir = os.path.dirname(pygame.__file__) # Grabbing the name of the local pg install
path_t_font = os.path.join(pygame_dir, 'freesansbold.ttf')
a = Analysis(['tic_tac_toe.py'],
pathex=[],
binaries=[],
datas=[(path_t_font, '.')], # Adding the font to data
.....
然后您需要将user_interface.py 中的第 12 行更改为:
# self.font = pygame.font.SysFont(None, 24) Instead of this use the code below
self.font = pygame.font.Font('freesansbold.ttf', 24)
不知道为什么会发生这种情况,但这是一个 hacky 修复。
如果您要使用 --onefile 模式,您还需要将其添加到 tic_tac_toe.py 脚本的顶部。
import sys, os
os.chdir(sys._MEIPASS)
从旧答案:
将详细标志添加到您的 PyInstaller 规格表中,以了解正在发生的事情。首先使用pyi-makespec <YOUR SCRIPT> 创建您的规格表,然后打开它创建的规格表。
转到exe=EXE 部分并添加这段代码。
exe = EXE(pyz,
a.scripts,
[('v', None, 'OPTION')], # Add this right here
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
现在使用自定义规格表捆绑您的包,然后运行它。您应该得到一个显示一些消息的控制台。这将告诉您正在加载的内容并让您了解正在发生的事情。