我有一個小型的蟒蛇街機遊戲,我已經使用pyInstaller轉換爲獨立的.exe。它可以在pygame下正常工作,但問題是我使用pickle來保存高分。我最初使用cmd作爲用戶輸入,因此在cmd中會說「請輸入你的名字」,無論你輸入什麼內容,都將使用pickle將其存儲在單獨的文件中。兩個問題:我不能在獨立的.exe中使用cmd(而且它看起來很醜),當我用pickle將它存儲在一個單獨的文件中時,我認爲它不包含在獨立文件中。我說「想」是因爲代碼永遠不會超過用戶輸入部分。獲取pygame屏幕上的用戶輸入以及如何存儲它
如何讓用戶輸入出現在屏幕上(在我自己的字體和位置中)而不是在cmd中?
和
如何可以包括用戶輸入文件(其存儲有泡菜)將被包括在該.exe?
這是我目前(全部在主循環):
if lives == 0:
username = input("Please type your name: ")
highscore = {username: points}
try:
with open("C:/Python35/highscore.txt", "rb") as highscoreBest:
highscoreBest = pickle.load(highscoreBest)
except EOFError:
with open("C:/Python35/highscore.txt", "wb") as highscoreBest:
pickle.dump(highscore, highscoreBest)
for (k, v), (k2, v2) in zip(highscore.items(), highscoreBest.items()):
if v >= v2:
with open("C:/Python35/highscore.txt", "wb") as highscoreBest:
pickle.dump(highscore, highscoreBest)
with open("C:/Python35/highscore.txt", "rb") as highscoreBest:
highscoreBest = pickle.load(highscoreBest)
for key, value in highscoreBest.items():
print("%s has the highscore of %s!" % (key, value))
highscoreText = highscorefont.render("Highscore %s" % (value), 1, textcolor)
gameOverText = font.render("GAME OVER", 1, textcolor)
scoreText = font.render("Score %s" % (points), 1, textcolor)
while 1:
screen.blit(gameOverText, (200, 400))
screen.blit(scoreText, (225, 450))
screen.blit(highscoreText, (235,500))
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
pygame.display.flip()
time.sleep(1)
感謝所有誰答覆。
我知道,我可以用EXE捆綁,但我不知道如何使用pyInstaller,因爲它會自動捆綁我需要的文件,所以我不知道如何手動添加文件。另外,我不知道如何安裝這些「GUI庫」。你可以再詳細一點嗎? –
剛剛更新了我的建議 – sr3z
謝謝,這非常有幫助,但我如何處理爲OcempGUI下載的'.gz'文件?所有「提取」選項都變灰。 –