用 peewee 阅读整个表格

问题描述 投票:0回答:1

我在mysql中有这段代码:

def get_table():
    cur = self.cnn.cursor()
    cur.execute("SELECT * FROM table")
    data = cur.fetchall()
    cur.close()
    return data

以列表形式返回整个表。然后我可以在另一个模块中使用它来填充 TreeView (tkinter):

for row in data:
    TreeView.insert('',END,text=row[0], values=(row[1],row[2],row[3],etc

这效果很好。但现在我想使用 Peewee 来做到这一点,并且我不知道如何返回到使用 TreeView 整个表的模块。我想过执行以下操作,但这不起作用。

def get_table():
    for row in Students.select():
       data = data + row.get()
    return data

我想我应该尝试根据每行的数据制作一个矩阵,但我不知道该怎么做。 预先感谢!

python peewee
1个回答
0
投票
def get_table():
    return list(Students.select())
© www.soinside.com 2019 - 2024. All rights reserved.