简体   繁体   中英

TTK Combobox does not style properly

I have been attempting to create a combobox that fits in with the rest of my UI; however the widget still looks like the default: 默认的 ttk 组合框

In my attempts, I have tried to "brute-force" the widget into adapting to the color with the following code but to no avail:

self.root = tk.Tk() # Parent Container

# Other UI elements declared

self.themeSel_combo_theme.configure(
    "TCombobox",
    background=self.theme.get('bg'),
    foreground=self.theme.get('bg'),
    fieldbackground=self.theme.get('bg'),
    darkcolor=self.theme.get('bg'),
    lightcolor=self.theme.get('bg'),
    selectbackground=self.theme.get('bg'),
    selectforeground=self.theme.get('bg'),
    bordercolor=self.theme.get('bg'),
    insertcolor=self.theme.get('bg'),
    insertwidth=self.theme.get('bg'), # It uses a color, not a size value
    arrowcolor=self.theme.get('bg')
)

self.themeSel_combo = ttk.Combobox(self.quickTheme_cont, style="TCombobox")

The code above was made using this website as a reference.

Note that self.theme.get('bg') returns #202020

Apologies for the inconvenience; I've decided to keep this thread in case someone else needs help with this. It turns out that using the following command for creating the parent container makes it so that ttk objects do not style properly:

self.root = tk.Tk()

Changing the aforementioned command to the following fixed the issue I was having:

self.root = tk.Toplevel()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM