我正在使用TKinter建立一个GUI,创建一个基本程序,允许我添加、更新、删除和查看我个人图书馆中的书籍。我在代码的两个部分上苦苦挣扎:
当我单击ViewRecords时,GUI中的文本框应该在一个列表中显示记录,每个项都显示在自己的行中。
它也不应该在每次按下按钮时复制列表。你知道吗
view_records = Button(root, text="View Records", width=12, command=view_command)
view_records.grid(row=3,column=3,columnspan=2,sticky='w’)
def view_command():
listings.delete(0,END) # does not duplicate entries for multiple clicks
for row in personal_library_backend.view():
listings.insert(END,row) # this does not list rows per index
这是我的后台脚本:
def insert(title, author, genre, year):
conn=sqlite3.connect("library.db")
cur=conn.cursor()
cur.execute("INSERT INTO books VALUES (NULL,?,?,?,?)",(title,author,genre,year))
conn.commit()
conn.close()
def view():
conn=sqlite3.connect("library.db")
cur=conn.cursor()
cur.execute("SELECT * FROM books")
rows=cur.fetchall()
conn.close()
return rows
当我运行这个程序时,我不断得到一个错误,在view\u命令函数中显示“坏文本索引0”。我好像想不通。有人能给我指出正确的方向吗?你知道吗
文本小部件的索引应该是one of these格式(即)行.列“或油箱端你的
0
不适合这些。你知道吗应将“删除行”更改为:
删除文本小部件中的所有内容。你知道吗
要使每个
row
出现在新行上,只需在插入row
之后手动插入新行。你知道吗相关问题 更多 >
编程相关推荐