[Python] ttk.Combobox selected text vanishes when focus is lost (clam theme, readonly)

Discussão em 'Python' iniciado por Stack, Agosto 4, 2025.

  1. Stack

    Stack Membro Participativo

    I'm new to python and recently started coding a combobox using the "clam" UI theme. However, the selected text vanishes when focus is lost from the dropdown? It seems confined to "clam" as other UI themes such as "alt" work fine.

    For example, the initial screen shows

    [​IMG]

    Click the dropdown icon

    [​IMG]

    Now, re-click the dropdown icon

    [​IMG]

    Notice the default value apples has vanished? I was expecting it to be visible.

    Example Code

    import tkinter as tk, tkinter.ttk as ttk

    root = tk.Tk()

    style = ttk.Style(root)
    style.theme_use("clam")
    style.configure("TCombobox", fieldbackground="white", background="white")
    style.map("TCombobox", fieldbackground=[("readonly", "white")], background=[("readonly", "white")])

    cb = ttk.Combobox(root, state="readonly", values=("apples", "oranges", "bananas"))
    cb.set("apples")
    cb.pack(padx=40, pady=40)

    root.mainloop()

    Continue reading...

Compartilhe esta Página