簡體   English   中英

pyinstaller 創建的程序崩潰

[英]Program created by pyinstaller crashes

如果我初始化"pyinstaller main.p ”並將我的所有項目文件移動到.exe方向,它會統計。 我可以在控制台中創建的菜單中做一些事情。

但是當我選擇開始時,游戲就卡住了。 我在 StackOverflow 上閱讀了有關更改項目中聲明字體的方式的文章,但我認為這還不夠。 整個游戲循環在一個名為game()的函數中,所以下面我將發布這個函數的代碼。

誰能幫我解決這個問題?

我嘗試使用pyinstaller GUI 版本,但它也不起作用。

def play(self):
    self.reset()
    self.random_field()

    while self.game:
        self.screen.fill(self.background_color_play)
        direction = self.event_catcher()
        if direction:
            self.move(direction)
            if direction != "back":
                self.random_field()
                if self.score > self.best:
                    self.best = self.score

        for i in range(self.size*self.size):
            self.tiles[i].update_color()
            pygame.draw.rect(self.screen, self.tiles[i].color, [self.tiles[i].x1, self.tiles[i].y1,
                                                                self.tiles[i].x2, self.tiles[i].y2])
            if self.tiles[i].value:
                self.message_display(text=str(self.tiles[i].value), x=(2*self.tiles[i].x1+self.tiles[i].x2)/2,
                                     y=(2*self.tiles[i].y1+self.tiles[i].y2)/2, font_size=100,
                                     color=self.tiles[i].font_color, font="Clear Sans Bold")

        # UNDO
        if self.size_of_stack:
            self.message_display(text=Screen.req_word("undo", self.lang)+": {}".format(self.stack.size()//len(self.tiles)),
                                 x=20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                                 color=(69, 69, 69), pos="left")
        else:
            self.message_display(text=Screen.req_word("undo", self.lang)+": 0",
                                 x=20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                                 color=(69, 69, 69), pos="left")

        # SCORE
        self.message_display(text=Screen.req_word("score", self.lang)+": {}".format(self.score),
                             x=self.screen_width*0.5, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                             color=(69, 69, 69))

        # BEST SCORE
        self.message_display(text=Screen.req_word("best", self.lang)+": {}".format(self.best),
                             x=self.screen_width-20, y=(self.screen_height-self.screen_width+10)/2, font_size=30,
                             color=(69, 69, 69), pos="right")

        self.clock.tick(self.fps)
        pygame.display.update()

    self.main_menu()

我希望它不會在另一台沒有安裝 python 的計算機上崩潰。 如果需要這里是完整的代碼

@Eric 我的 .spec 文件:

# -*- mode: python -*-

block_cipher = None


a = Analysis(['main.py'],
             pathex=['C:\\Projekty Pythona\\2048'],
             binaries=[],
             datas=[],
             hiddenimports=[],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          a.binaries,
          a.zipfiles,
          a.datas,
          [],
          name='main',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          runtime_tmpdir=None,
          console=True )

今天我會嘗試發現有問題的陳述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM