From a196337bce8677311aad278172f652d2ee64d643 Mon Sep 17 00:00:00 2001 From: kun <13098278+w52020031129@user.noreply.gitee.com> Date: Sat, 1 Jun 2024 23:57:38 +0800 Subject: [PATCH] 6-1 --- sql.py | 3 +-- visualization.py | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/sql.py b/sql.py index 992ced9..f88cf84 100644 --- a/sql.py +++ b/sql.py @@ -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() diff --git a/visualization.py b/visualization.py index 3259f3b..78dd7be 100644 --- a/visualization.py +++ b/visualization.py @@ -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 # #布局管理器