CustomTkinter icon indicating copy to clipboard operation
CustomTkinter copied to clipboard

CTKEntry placeholder text not always visible.

Open joranv1 opened this issue 3 years ago • 4 comments

When I start my app, the placeholder text of some CTKEntry widgets are not visible.

image

If I then select one of those entry widgets (so it's focused) and then select something else (to remove the focus), the placeholder text comes back.

Here's a screen recording of the issue:

https://user-images.githubusercontent.com/41532982/205989315-49787784-499a-4569-b01b-77b808a3917e.mov

I'm using the latest version (5.0.1), Python 3.11 on macOS Ventura.

joranv1 avatar Dec 06 '22 18:12 joranv1

How do you create the entries? Can you show your code?

TomSchimansky avatar Dec 06 '22 20:12 TomSchimansky

Here's the code of how the entries are created:

name_exercise_entry = ctk.CTkEntry(master=action_frame, border_color=("#b2b2b2", "#535353"), placeholder_text_color=("#858585", "#afafaf"),
                                   text_color=("black", "white"), fg_color=("white", "#414141"), width=292, placeholder_text="Exercise name")
name_exercise_entry.place(relx=0.03, rely=0.27, anchor=ctk.W)
reps_entry = ctk.CTkEntry(master=action_frame, border_color=("#b2b2b2", "#535353"), placeholder_text_color=("#858585", "#afafaf"),
                          text_color=("black", "white"), fg_color=("white", "#414141"), width=292, placeholder_text="Amount of reps")
reps_entry.place(relx=0.03, rely=0.32, anchor=ctk.W)
sets_entry = ctk.CTkEntry(master=action_frame, border_color=("#b2b2b2", "#535353"), placeholder_text_color=("#858585", "#afafaf"),
                          text_color=("black", "white"),
                          fg_color=("white", "#414141"), width=292, placeholder_text="Amount of sets")
sets_entry.place(relx=0.03, rely=0.37, anchor=ctk.W)
weight_entry = ctk.CTkEntry(master=action_frame, border_color=("#b2b2b2", "#535353"), placeholder_text_color=("#858585", "#afafaf"),
                            text_color=("black", "white"),
                            fg_color=("white", "#414141"), width=292, placeholder_text="Weight (leave blank for no weight)")
weight_entry.place(relx=0.03, rely=0.42, anchor=ctk.W)

The full source code of the app can be found here

joranv1 avatar Dec 06 '22 22:12 joranv1

I found the cause of this issue. Turns out it's a bug and the placeholder text gets deleted when you clear the text in the entry. When you call entry.delete(0, 'end'), it removes the filled in text but ALSO the placeholder text which it shouldn't. When clearing the entry, only the text the user filled in should be removed, not the placeholder text (which is just a hint to tell the user what info he should enter in the entry). Here's some code to reproduce this issue:

import customtkinter as ctk


def clear_entry():
    print("clearing entry...")
    entry.delete(0, 'end')


app = ctk.CTk()

width = 600
height = 400

width_screen = app.winfo_screenwidth()
height_screen = app.winfo_screenheight()

spawn_x = int((width_screen / 2) - (width / 2))
spawn_y = int((height_screen / 2) - (height / 2))

app.geometry(f"{width}x{height}+{spawn_x}+{spawn_y}")
app.title("Bug")

main_frame = ctk.CTkFrame(app, fg_color="#e2e2e2")
main_frame.pack(anchor="w", fill="both", expand=True)

clear_entry_button = ctk.CTkButton(master=main_frame, width=80, fg_color="#3C99DC", text="Clear entry", command=clear_entry)
clear_entry_button.place(relx=0.03, rely=0.1, anchor=ctk.W)

entry = ctk.CTkEntry(master=main_frame, width=292, placeholder_text="Placeholder text")
entry.place(relx=0.03, rely=0.2, anchor=ctk.W)

app.mainloop()

joranv1 avatar Dec 25 '22 12:12 joranv1

I will have a look at this!

TomSchimansky avatar Dec 27 '22 00:12 TomSchimansky