import tkinter as tk
from tkinter import ttk
import get_bookpage
def book_page(url, result_frame, bookpage_frame, window):
result_frame.pack_forget() # 隐藏当前界面
bookpage_frame.pack(fill=tk.BOTH, expand=True)
window.title('爬书 - 书籍章节') # 修改窗口标题
# 创建表格
tree_style = ttk.Style(bookpage_frame)
tree_style.configure('Treeview.Heading', font=('Arial', 14)) # 修改标题的字体大小
tree = ttk.Treeview(bookpage_frame, columns=('章节名称'), show='headings')
tree.heading("章节名称", text="章节名称", anchor=tk.W)
# 创建垂直滚动条
scrollbar = tk.Scrollbar(bookpage_frame, orient="vertical", command=tree.yview)
tree.configure(yscrollcommand=scrollbar.set)
tree.delete(*tree.get_children())
# 重新填充树
page_name_link = get_bookpage.get_detail_name_and_link(url) # 获取页面书籍详情信息
for name, link in page_name_link.items():
item_id = tree.insert('', 'end', values=(name,), tags=('button_tag', link))
tree.tag_bind(link, '<Double-Button-1>', lambda event, item_ids=item_id, keys=link: kong())
# 将表格和滚动条放置在界面上
tree.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
# 定义返回函数
def return_to_result_frame():
tree.delete(*tree.get_children())
bookpage_frame.pack_forget() # 隐藏书籍章节界面
result_frame.pack(fill=tk.BOTH, expand=True) # 显示结果界面
# 添加返回按钮
return_button = tk.Button(bookpage_frame, text="返回", command=return_to_result_frame)
return_button.pack(side=tk.BOTTOM, padx=10, pady=10)
# 定义空函数
def kong():
pass
我想重新进入界面后新数据覆盖旧数据,而不是这样应该怎么做