From eb62e2e82ff81890020e9d1fdeb3e8a8cff7f03d Mon Sep 17 00:00:00 2001 From: CNlaojing <154053522+CNlaojing@users.noreply.github.com> Date: Sat, 8 Mar 2025 09:51:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=9F=E6=88=90=E8=8D=89?= =?UTF-8?q?=E7=A8=BF=E5=90=8E=E6=98=BE=E7=A4=BA=E5=AD=97=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/main_tab.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ui/main_tab.py b/ui/main_tab.py index 2ca6add..a5f66d4 100644 --- a/ui/main_tab.py +++ b/ui/main_tab.py @@ -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("", update_word_count) + self.chapter_result.bind("", 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)