kun 6 months ago
parent fa191daaa6
commit a196337bce

@ -61,10 +61,9 @@ class BookDatabase:
if len(name.strip()) == 0:
cursor.execute(f"SELECT * FROM {self.table_name}")
book_list = cursor.fetchall()
return book_list
else:
cursor.execute(f"SELECT * FROM {self.table_name} WHERE name LIKE '%{name}%'")
cursor.execute(f"SELECT * FROM {self.table_name} WHERE name LIKE '%{name}%' or author LIKE '%{name}%' ")
book_list = cursor.fetchall()
return book_list
self.connection.commit()

@ -40,13 +40,14 @@ def on_login_button_click():
# search_label = tk.Label(show, text="搜索:", pady=10)
# search_label.pack()
def serch_book():
search = search_entry.get()
book_collection = db_data.get_book_list(search)
print("我搜索了:")
print(book_collection)
print("我搜索了:{}".format(search))
# 清空当前 Treeview
tree.delete(*tree.get_children())
book_id = 1
for book in book_collection:
print(type(book))
tree.insert("", "end", text=book_id, values=(
book["name"], book["url"], book["star"], book["star_people"], book["author"], book["translater"],
book["publisher"], book["pub_year"], book["price"], book["comment"]))
@ -54,7 +55,6 @@ def on_login_button_click():
search_button = tk.Button(show, text="搜索", command=serch_book, width=30, font=15)
search_button.pack()
search_entry = tk.Entry(show, width=30)
search=search_entry.get()
search_entry.pack()
# 显示书籍集合数据
@ -86,7 +86,7 @@ def on_login_button_click():
book_id=1
for book in book_collection:
print(type(book))
tree.insert("", "end", text=book_id, values=(book["name"], book["url"], book["star"], book["star_people"], book["author"], book["translater"], book["publisher"], book["pub_year"], book["price"], book["comment"]))
book_id=book_id+1
# #布局管理器

Loading…
Cancel
Save