素胚勾勒不出你
您将需要创建一个 .spec 文件并提及您要在其中包含的内容,例如字体或其他图像。# -*- mode: python -*-block_cipher = Nonea = Analysis(['your python file.py'], pathex=['C:\\path\\to\\directory'], # just the directory not the file binaries=[], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher)a.datas += [('ttf file','path\\to\\ttf\\file', "DATA")]pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='Your App Name', debug=False, strip=False, upx=True, console=False # set True if command prompt window needed)在游戏所在的实际 python 文件中包含此内容。def resource_path(relative_path): try: base_path = sys._MEIPASS except Exception: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path)每当您想加载字体时,都可以这样做。font = pygame.font.Font(resource_path("Font.ttf"), size)在你的主 python 文件中有了它之后,在你的终端中输入你创建的规范文件。pyinstaller yourspecfile.spec这将创建您的可执行文件,它应该自己工作。这是我以前项目中的规范文件的样子 # - - mode: python - -block_cipher = Nonea = Analysis(['lol.py'], pathex=['C:\\games\\snake'], binaries=[], datas=[], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher)a.datas += [('8min.ttf','C:\\games\\snake\\8min.ttf', "DATA")]pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, name='Snake', debug=False, strip=False, upx=True, console=False)