python - 在付费游戏中将 sqlite 数据库显示为表格
问题描述
我正在尝试将基本的 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
我希望这些数字都与“分数”这个词的结尾对齐。任何帮助将不胜感激,因为我尝试了一些事情,但似乎没有任何工作。
解决方案
要么使用等宽字体,要么分别渲染每一列的文本:
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
推荐阅读
- ios - 无法检测到ios 13+以上的设备平台
- css - 如何在 Nuxtjs 中为每个布局包含本地(非全局)样式表文件
- jhipster - JHipster 网关应用程序登录失败
- javascript - Google Apps 脚本:类表示法和新对象
- python - 如何从python中的字典中获取值?
- reactjs - 如何在同一个根域下创建 2 个 PWA
- javascript - 编写一个 JavaScript 控制台程序来读取输入文件并将句子转换为首字母缩写词
- javascript - 如何在 CKEditor 4 中设置默认字体
- c++ - 使用动态编程的具有分区约束的 Max Sum 子数组
- javascript - 如何从阴影根元素中获取文本?