Skip to content

Commit

Permalink
fixed bug when configuring place_holder in CTkEntry widget TomSchiman…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomSchimansky committed Sep 13, 2022
1 parent 9a144bf commit 64c8b83
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions customtkinter/widgets/ctk_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, *args,
self.entry.bind('<FocusOut>', self.entry_focus_out)
self.entry.bind('<FocusIn>', self.entry_focus_in)

self.set_placeholder()
self.activate_placeholder()
self.draw()

def set_scaling(self, *args, **kwargs):
Expand Down Expand Up @@ -176,6 +176,8 @@ def configure(self, require_redraw=False, **kwargs):
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")
Expand All @@ -202,7 +204,7 @@ def configure(self, require_redraw=False, **kwargs):

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

Expand All @@ -211,7 +213,7 @@ def set_placeholder(self):
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

Expand All @@ -221,19 +223,19 @@ def clear_placeholder(self):
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)

Expand Down

0 comments on commit 64c8b83

Please sign in to comment.