[Python] Why is the custom tkinter placeholder text for an entry box ignored?

Discussão em 'Python' iniciado por Stack, Maio 9, 2025.

  1. Stack

    Stack Membro Participativo

    import tkinter as tk
    import customtkinter as ui

    ui.set_appearance_mode("dark")
    ui.set_default_color_theme("dark-blue")

    root = ui.CTk()
    root.geometry("500x350")

    frame = ui.CTkFrame(master=root)
    frame.pack(pady=20, padx=60, fill="both", expand=True)

    label = ui.CTkLabel(master=frame, text="Login System", font=("Roboto", 24))
    label.pack(pady=12, padx=10)

    username = tk.StringVar()
    entry1 = ui.CTkEntry(master=frame, textvariable=username, placeholder_text="Username")
    entry1.pack(pady=12, padx=10)

    password = tk.StringVar()
    entry2 = ui.CTkEntry(master=frame, textvariable=password, placeholder_text="Password", show="*")
    entry2.pack(pady=12, padx=10)

    def login():
    print(username.get())
    print(password.get())

    button = ui.CTkButton(master=frame, text="Login", command=login)
    button.pack(pady=12, padx=10)

    checkbox = ui.CTkCheckBox(master=frame, text="Remember Me")
    checkbox.pack(pady=12, padx=10)

    root.mainloop()


    Here is my code. The problem is that the placeholder text doesn't show up when I pass a text variable argument.

    entry1 = ui.CTkEntry(master=frame, placeholder_text="Username")


    shows the placeholder but doesn't pass the textvariable

    entry1 = ui.CTkEntry(master=frame, textvariable=username, placeholder_text="Username")


    passes the textvariable but doesn't show the placeholder

    I've seen similar questions but they don't work for the custom tkinter widget and they don't use the placeholder argument.

    Continue reading...

Compartilhe esta Página