From 679177e839a8d45fc051b29045989f1763be0a10 Mon Sep 17 00:00:00 2001 From: CNlaojing <154053522+CNlaojing@users.noreply.github.com> Date: Sun, 9 Mar 2025 18:33:17 +0800 Subject: [PATCH] Update directory_tab.py --- ui/directory_tab.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/ui/directory_tab.py b/ui/directory_tab.py index 09b7aba..2a26c64 100644 --- a/ui/directory_tab.py +++ b/ui/directory_tab.py @@ -15,12 +15,23 @@ def build_directory_tab(self): load_btn = ctk.CTkButton(self.directory_tab, text="加载 Novel_directory.txt", command=self.load_chapter_blueprint, font=("Microsoft YaHei", 12)) load_btn.grid(row=0, column=0, padx=5, pady=5, sticky="w") + self.directory_word_count_label = ctk.CTkLabel(self.directory_tab, text="字数:0", font=("Microsoft YaHei", 12)) + self.directory_word_count_label.grid(row=0, column=1, padx=5, pady=5, sticky="w") + save_btn = ctk.CTkButton(self.directory_tab, text="保存修改", command=self.save_chapter_blueprint, font=("Microsoft YaHei", 12)) - save_btn.grid(row=0, column=0, padx=5, pady=5, sticky="e") + save_btn.grid(row=0, column=2, padx=5, pady=5, sticky="e") self.directory_text = ctk.CTkTextbox(self.directory_tab, wrap="word", font=("Microsoft YaHei", 12)) + + def update_word_count(event=None): + text = self.directory_text.get("0.0", "end") + count = len(text) - 1 + self.directory_word_count_label.configure(text=f"字数:{count}") + + self.directory_text.bind("", update_word_count) + self.directory_text.bind("", update_word_count) TextWidgetContextMenu(self.directory_text) - self.directory_text.grid(row=1, column=0, sticky="nsew", padx=5, pady=5) + self.directory_text.grid(row=1, column=0, sticky="nsew", padx=5, pady=5, columnspan=3) def load_chapter_blueprint(self): filepath = self.filepath_var.get().strip()