打印lis中的高分

2024-06-01 10:47:48 发布

您现在位置:Python中文网/ 问答频道 /正文

所以在我的游戏菜单中,我希望能够逐行打印出一个.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)

Tags: 文件代码txt游戏def菜单sfpygame
1条回答
网友
1楼 · 发布于 2024-06-01 10:47:48

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)

相关问题 更多 >