CustomTkinter
CustomTkinter copied to clipboard
Associating a tk.StringVar with CTkEntry erases placeholder text
Hello.
I have added StringVar to CTkEntry widget, using the textvariable parameter. I am then binding the key release event to a function. The idea being that as the user types, the characters are converted to uppercase:
self.tk_new_db_account_name = tk.StringVar(master=self.frm_new_entry)
self.ent_new_db_account_name = ctk.CTkEntry(master=self.frm_new_entry,
placeholder_text='Database username',
textvariable=self.tk_new_db_account_name)
self.ent_new_db_account_name.grid(row=row, column=0, padx=default_padx, pady=default_pady)
self.ent_new_db_account_name.bind("<KeyRelease>", self.db_account_caps)
In case it is relevant (unlikely), db_account_caps method looks like this:
def db_account_caps(self, event):
self.tk_new_db_account_name .set(self.tk_new_db_account_name .get().upper())
The capitalisation works, however this causes the 'Database username', placeholder text, to be ignored (or erased). If I remove the StringVar, the placeholder text reappears.
This is happening with CustomTkinter 4.6.3.
Is this a bug or am I missing something?
Thanks.
That's intended, because I couldn't get it to work properly, it was too much work so I just disabled the placeholder for variables. Maybe I will try to do it again n the future.
@avalon60 It is not possible to use the textvariable
and placeholder_text
at the same time because the textvariable
will replace the placeholder_text
.
However, there is a workaround like this
entry = CTkEntry(frame,placeholder_text="Enter Somthing..")
entry.pack()
submitButton = CTkButton(
frame,
font=("",32),
text="Submit",
command=lambda: print(entry.get())
)
Instead of using StringVar()
you can get the value directly from the entry
it self