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)
4

1 回答 1

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)
于 2013-11-15T15:10:53.863 回答