首页 > 解决方案 > 如何使用 python 在树视图中显示来自 sqlite 的数据

问题描述

我有这个类,但是当我运行这个应用程序时没有显示任何东西..我的表格中有七列,表格的标题出现在我的应用程序上,只是来自 sqlite 的数据不显示..我该如何解决这个问题?

class Students:
db_name = 'Lutai.db'

def run_query(self, query, parameters = ()):
    with sqlite3.connect (self.db_name) as conn:
        cursor = conn.cursor()
        query_result = cursor.execute(query,parameters)
        conn.commit()
    return query_result

def viewing_records(self):
    records = self.tree.get_children()
    for element in records:
        self.tree.delete(element)
    query = "SELECT * FROM student ORDER BY nume DESC"
    db_rows = self.run_query(query)
    for row in db_rows:
        self.tree.insert('', 0, text=row[1], values=row[2])

我的班级还包含标签等照片: 点击这里 图片来自 imgur.com

标签: pythonsqlite

解决方案


推荐阅读