Python 显示整个数据库数据tkinter sqlite3
我试图在窗口上打印数据库中的历史记录,但我的程序只显示两行(甚至没有顺序)。有什么问题吗? 打印时,我正确地获取了数据,但无法在窗口中获取数据。 对我来说这毫无意义Python 显示整个数据库数据tkinter sqlite3,python,tkinter,sqlite,Python,Tkinter,Sqlite,我试图在窗口上打印数据库中的历史记录,但我的程序只显示两行(甚至没有顺序)。有什么问题吗? 打印时,我正确地获取了数据,但无法在窗口中获取数据。 对我来说这毫无意义 def his(self, database, progx): con = sqlite3.connect(database) with con: cur = con.cu
def his(self, database, progx):
con = sqlite3.connect(database)
with con:
cur = con.cursor()
cur.execute('SELECT * FROM ' + progx + ' ORDER BY id DESC ')
index=3
for row in cur.fetchall():
print(row) #this works just fine
Label(self, text=row[1]).grid(row=index, column=0)
Label(self, text=row[2]).grid(row=index, column=1)
Label(self, text=row[3]).grid(row=index, column=2)
Label(self, text=row[4]).grid(row=index, column=3)
Label(self, text=row[5]).grid(row=index, column=4)
Label(self, text=row[6]).grid(row=index, column=5)
Label(self, text=row[7]).grid(row=index, column=6)
Label(self, text=row[8]).grid(row=index, column=7)
Label(self, text=row[9]).grid(row=index, column=8)
Label(self, text=row[10]).grid(row=index, column=9)
Label(self, text=row[11]).grid(row=index, column=10)
Label(self, text=row[12]).grid(row=index, column=11)
Label(self, text=row[13]).grid(row=index, column=12)
Label(self, text=row[14]).grid(row=index, column=13)
hist.update()
index=+1
它没有正确地遍历小部件,因为索引是错误的。 更改: 致:
对于范围(14)中的n:标签(self,text=row[n+1])。网格(row=index,column=n)
将消除所有难看的重复代码谢谢,但这并不能解决我的问题。是的,你是对的。只是一个小提示,供将来使用。在我看来,问题一定是由代码中的其他内容引起的。如果打印出来的数据看起来不错,我看不出有什么理由不起作用。请创建一个,最好是不依赖外部数据库的数据库。例如,您可以使用预定义的列表来模拟数据。非常感谢,我从昨天起就一直在努力解决这个问题。
index=+1
index += 1