1

How can I make the ttk.combobox like the one in this picture(ttk-Breeze). enter image description here

CODE:

from tkinter import *
from tkinter import  ttk

gray1 = "gray15"
gray2 = "gray20"
gray3 = "gray80"

class Theme():
    def __init__(self):
        # ================= CUSTOM THEME FOR COMBOBOX
        style = ttk.Style()
        style.theme_create('custom_style',
                           parent='alt',
                                   # ================= COMBOBOX
                           settings={'TCombobox':
                                         {'configure':
                                              {
                                                   'fieldbackground': gray2,
                                                   'background': gray2,
                                                   'relief': FLAT,
                                                   'state': DISABLED
                                                  #  "highlightthickness": [0],
                                                  #  "borderwidth": [0],
                                               }
                                          },
                                     }
                           )
        style.theme_use('custom_style')

class App():
    def __init__(self, root):
        self.root = root
        Theme.__init__(self)

        options = ['Don', 'Tom', 'Harry']
        cb = ttk.Combobox(self.root, values=options, state='readonly')
        cb.pack()

def main():
    root = Tk()
    App(root)
    root.config(bg=gray1)
    root.geometry('300x300')
    root.option_add('*TCombobox*Listbox.Background', gray2)
    root.option_add('*TCombobox*Listbox.Foreground', gray3)
    root.mainloop()

if __name__ == '__main__':
    main()

When I use this theme there is still a border around the combobox and listbox too. I want to achieve completely flat ttk.combobox.

  • I came to know that there are different types of theme styles available for different OS. Which you can get by running `style.theme_names()`. For linux(which I have), you get `('clam', 'alt', 'default', 'classic')`. So if I change `parent='alt'` to `parent='default'`, I get totally flat Combobox. But then I don't know how to give `'highlightthickness'` and `'highlightcolor'`. I've been trying, once I get the result I wanted I'll post the answer with the result. Till then if anyone finds the answer pls let me know. – Milind Khobragade Nov 13 '21 at 09:01

0 Answers0