添加生成草稿后显示字数

This commit is contained in:
CNlaojing
2025-03-08 09:51:37 +08:00
committed by GitHub
parent 51510449a9
commit eb62e2e82f
+12 -2
View File
@@ -33,14 +33,24 @@ def build_left_layout(self):
self.left_frame.grid_rowconfigure(4, weight=1)
self.left_frame.columnconfigure(0, weight=1)
chapter_label = ctk.CTkLabel(self.left_frame, text="本章内容 (可编辑)", font=("Microsoft YaHei", 12))
chapter_label.grid(row=0, column=0, padx=5, pady=(5, 0), sticky="w")
self.chapter_label = ctk.CTkLabel(self.left_frame, text="本章内容可编辑 字数:0", font=("Microsoft YaHei", 12))
self.chapter_label.grid(row=0, column=0, padx=5, pady=(5, 0), sticky="w")
# 章节文本编辑框
self.chapter_result = ctk.CTkTextbox(self.left_frame, wrap="word", font=("Microsoft YaHei", 14))
TextWidgetContextMenu(self.chapter_result)
self.chapter_result.grid(row=1, column=0, sticky="nsew", padx=5, pady=(0, 5))
def update_word_count(event=None):
text = self.chapter_result.get("0.0", "end")
count = len(text) - 1 # 减去最后一个换行符
self.chapter_label.configure(text=f"本章内容(可编辑) 字数:{count}")
self.chapter_result.bind("<KeyRelease>", update_word_count)
self.chapter_result.bind("<ButtonRelease>", update_word_count)
# Step 按钮区域
self.step_buttons_frame = ctk.CTkFrame(self.left_frame)
self.step_buttons_frame.grid(row=2, column=0, sticky="ew", padx=5, pady=5)