【发布时间】:2019-01-05 00:55:15
【问题描述】:
我正在 python 3.6.6 中制作一个简单的 Tkinter GUI,但我无法从数据库中获取数据来填充列表框。
我的问题是什么?当我想用来自 sqlite3 数据库的现有数据填充列表框时,我单击“刷新数据”按钮并遇到错误。 我的代码应该选择第一个冒号中的所有行并将所有内容放在列表框中。 重要的代码行如下:
db_conn = sqlite3.connect("dbs/entries.db")
cursor = db_conn.cursor()
def updateListbox(self):
#Delete items in the list box
self.listOfEntries.delete(0, "END")
#Get users from the db
try:
result = self.cursor.execute("SELECT Name FROM Entries")
# Receive a list of lists that hold the result
for row in result.fetchall():
name = row[0]
# Put the student in the list box
self.listOfEntries.insert(name)
except sqlite3.OperationalError:
print("The Table Doesn't Exist")
except:
print("1: Couldn't Retrieve Data From Database")
每次单击“刷新数据”按钮时,我都会收到“1:无法从数据库中检索数据”错误。 我的代码的结果应该只是填充列表框。
【问题讨论】:
-
暂时删除
except子句或在其中添加traceback.print_exc()以获取更多错误详情。如果您需要进一步的帮助,请编辑问题以显示回溯。 -
insert方法需要两个参数。