How to set a color for a Combobox in all windows How to set a color for a Combobox in all windows tkinter tkinter

How to set a color for a Combobox in all windows


Having more than one instance of Tk in a program is a big no. Read this answer. Quoting it here :

Every tkinter program needs exactly one instance of Tk. Tkinter is a wrapper around an embedded tcl interpreter. Each instance of Tk gets its own copy of the interpreter, so two Tk instances have two different namespaces.

If you need multiple windows, create one instance of Tk and then additional windows should be instances of Toplevel.

So, if you need multiple windows, use a Toplevel. Here is an example.

P.S. For styling a ttk widget, read the docs. It can be done easily using .configure() of ttk.Style().

import tkinter as tkimport tkinter.ttk as ttkr = tk.Tk()def callback():    r2 = tk.Toplevel()    c2 = ttk.Combobox(r2, style='ARD.TCombobox')    c2.pack()b = tk.Button(r, text = 'Open', command = callback)b.pack()combostyle = ttk.Style()combostyle.configure('ARD.TCombobox', background="#ffcc66", fieldbackground="#ffff99")c = ttk.Combobox(style='ARD.TCombobox')c.pack()r.mainloop()