【问题标题】:display sqlite database as a table in paygames在付费游戏中将 sqlite 数据库显示为表
【发布时间】:2022-12-12 08:20:27
【问题描述】:

我正在尝试将基本的 SQLite 数据库显示为 pygame 中的表。它包含玩家的用户名和分数。我现在的代码显示了它,但它并没有很好地对齐。编码:

def leader_board():
    i = 35
    messg = font_style.render(f'PLAYER                  SCORE', True, yellow)
    dis.blit(messg, [dis_width / 5, (700 / 4) + 5])
    cur.execute('SELECT * FROM snake_score ORDER BY score desc LIMIT 10')

    rows = cur.fetchall()
    for row in rows:
        mesgg = font_style.render('{:>3} {:30}'.format(row[0], row[1]), True, yellow)
        dis.blit(mesgg, [dis_width / 5, (700 / 4) + i + 5])
        i += 35

这是我从中得到的结果:

我希望所有数字都与“分数”一词的末尾对齐。任何帮助将不胜感激,因为我尝试了一些方法但似乎都没有用。

【问题讨论】:

  • 使用等宽字体或分别呈现每列的文本。

标签: python sqlite pygame


【解决方案1】:

使用等宽字体或分别呈现每列的文本:

def leader_board():
    i = 35
    column_space = 400

    head1 = font_style.render(f'PLAYER', True, yellow)
    head2 = font_style.render(f'SCORE', True, yellow)
    dis.blit(head1, [dis_width / 5, (700 / 4) + 5])
    dis.blit(head2, [dis_width / 5 + column_space, (700 / 4) + 5])
    
    cur.execute('SELECT * FROM snake_score ORDER BY score desc LIMIT 10')
    rows = cur.fetchall()
    for row in rows:
        
        column1 = font_style.render('{:>3}'.format(row[0]), True, yellow)
        column2 = font_style.render('{:30}'.format(row[1]), True, yellow)
        dis.blit(column1, [dis_width / 5, (700 / 4) + i + 5])
        dis.blit(column2, [dis_width / 5 + column_space, (700 / 4) + i + 5])

        i += 35

【讨论】:

    猜你喜欢
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多