Reputation: 968
To set the style for the ttk.Combobox, I can do something like this:
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
combostyle = ttk.Style()
combostyle.theme_create('combostyle', parent='alt',
settings = {'TCombobox':
{'configure':
{'selectbackground': 'blue',
'fieldbackground': 'red',
'background': 'green'
}}}
)
combostyle.theme_use('combostyle')
combo = ttk.Combobox(root, values=['1', '2', '3'])
combo['state'] = 'readonly'
combo.pack()
entry = tk.Entry(root)
entry.pack()
root.mainloop()
But that sets the theme for all tkinter and ttk widgets. I want to set the style for only the Combobox. How can I do this?
I am using Python 3 on Windows 10.
Any help is greatly appreciated.
Upvotes: 1
Views: 7889
Reputation: 1758
Your original method configures a global theme. To get a theme to be attached to one component you have to create it and attach it to the widget class.
combostyle.configure('MyCustomStyleName.TCombobox', selectbackground = 'blue', ........)
combo = ttk.Combobox(root, values=['1', '2', '3'], style = 'MyCustomStyleName.TCombobox')
Upvotes: 1