2013-11-15 39 views
0

因此,在我的遊戲菜單中,我希望能夠逐行打印出.txt文件中的高分,但是使用當前的代碼,它只是將所有分數添加到一個行可能有人請幫忙嗎?,我使用Livewires和Pygame。在列表中打印出高分

def highscores(self): 

     sf = open('highscore.txt', 'r') 
     highscores = sf.readlines() 
     sf.close() 

     thescores = games.Text(value = highscores, size = 32, color = color.green, 
        top = 130, right = 320) 

     games.screen.add(thescores) 

回答

2

highscores是一個列表,所以你需要遍歷它:

def highscores(self): 

     sf = open('highscore.txt', 'r') 
     highscores = sf.readlines() 
     sf.close() 
     top = 130 

     for highscore in highscores: 
      thescores = games.Text(value = highscore, size = 32, color = color.green, 
      top = top+10, right = 320) 
      games.screen.add(thescores) 
+1

我正要書寫相同的答案。請注意,您應該調整每一行的「頂部」值,否則所有文本行將被繪製在彼此之上。 – sloth

+0

這仍然打印出與以前相同的內容,除了現在打印出來的高分都在它們的周圍有括號,它們在列表中告訴我。這可能是錯誤的Livewires圖書館 –

+0

此外,'value = highscores'應該是'value = highscore' – sloth