From 64c8b8345dc7ea4d6bad3fefb1b98af67b7dccc0 Mon Sep 17 00:00:00 2001 From: TomSchimansky Date: Tue, 13 Sep 2022 21:47:50 +0200 Subject: [PATCH] fixed bug when configuring place_holder in CTkEntry widget #330 --- customtkinter/widgets/ctk_entry.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/customtkinter/widgets/ctk_entry.py b/customtkinter/widgets/ctk_entry.py index 3dbe89f..ef6171c 100644 --- a/customtkinter/widgets/ctk_entry.py +++ b/customtkinter/widgets/ctk_entry.py @@ -77,7 +77,7 @@ class CTkEntry(CTkBaseClass): self.entry.bind('', self.entry_focus_out) self.entry.bind('', self.entry_focus_in) - self.set_placeholder() + self.activate_placeholder() self.draw() def set_scaling(self, *args, **kwargs): @@ -176,6 +176,8 @@ class CTkEntry(CTkBaseClass): if self.placeholder_text_active: self.entry.delete(0, tkinter.END) self.entry.insert(0, self.placeholder_text) + else: + self.activate_placeholder() if "placeholder_text_color" in kwargs: self.placeholder_text_color = kwargs.pop("placeholder_text_color") @@ -202,7 +204,7 @@ class CTkEntry(CTkBaseClass): self.entry.configure(**kwargs) # pass remaining kwargs to entry - def set_placeholder(self): + def activate_placeholder(self): if self.entry.get() == "" and self.placeholder_text is not None and (self.textvariable is None or self.textvariable == ""): self.placeholder_text_active = True @@ -211,7 +213,7 @@ class CTkEntry(CTkBaseClass): self.entry.delete(0, tkinter.END) self.entry.insert(0, self.placeholder_text) - def clear_placeholder(self): + def deactivate_placeholder(self): if self.placeholder_text_active: self.placeholder_text_active = False @@ -221,19 +223,19 @@ class CTkEntry(CTkBaseClass): self.entry[argument] = value def entry_focus_out(self, event=None): - self.set_placeholder() + self.activate_placeholder() def entry_focus_in(self, event=None): - self.clear_placeholder() + self.deactivate_placeholder() def delete(self, *args, **kwargs): self.entry.delete(*args, **kwargs) if self.entry.get() == "": - self.set_placeholder() + self.activate_placeholder() def insert(self, *args, **kwargs): - self.clear_placeholder() + self.deactivate_placeholder() return self.entry.insert(*args, **kwargs)