首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >打印出列表中的高分

打印出列表中的高分
EN

Stack Overflow用户
提问于 2013-11-15 23:05:00
回答 1查看 101关注 0票数 0

所以在我的游戏菜单中,我希望能够从.txt文件中逐行打印出高分,但在我当前的代码中,它只是将所有的分数添加到一行中,有人能帮帮我吗?,我使用的是Livewires和Pygame。

代码语言:javascript
复制
    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)
EN

回答 1

Stack Overflow用户

发布于 2013-11-15 23:10:54

highscores是一个列表,所以你需要遍历它:

代码语言:javascript
复制
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)
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20004078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档