1

I'm trying to style a combobox widget scrollbar. I would like to set the trough color and size. I have been able set the size by changing the arrowsize parameter as in the code below. This is undesirable though because it changes all vertical scrollbars for all widgets. I would like to target specific widgets.

import tkinter as tk
import tkinter.ttk as ttk


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        self.title('Default Demo')
        self.geometry('420x200')

        style = ttk.Style()
        style.configure('my.TCombobox', arrowsize=30)
        style.configure('Vertical.TScrollbar', arrowsize=28)
        # style.configure('my.TCombobox.Vertical.TScrollbar', arrowsize=28)

        values = []
        for idx in range(1, 50):
            values.append(f'Testing-{idx}')

        cbo = ttk.Combobox(self, values=values, style='my.TCombobox')
        cbo.grid(ipady=5)


def main():
    app = App()
    app.mainloop()


if __name__ == '__main__':
    main()
Daniel Huckson
  • 1,157
  • 1
  • 13
  • 35
  • If you want different styles then you need to creat some. You can do more than one costum styled Scrollbar and add them to the widget you want. Maybe I miss the problem here. – Thingamabobs May 28 '20 at 18:27
  • You also need to take a look a this for your color – Thingamabobs May 28 '20 at 18:32
  • @Atlas435, I'm trying to style the scrollbar in the combobox dropdown. I don't know how to address it. I tried the commented out code above but it did nothing. – Daniel Huckson May 28 '20 at 19:23

1 Answers1

1

The combobox's scrollbar is not directly accessible through the python interface, but you can change its style through the tcl interpreter.

First, give a name to the combobox's dropdown:

self.tk.eval('set popdown [ttk::combobox::PopdownWindow %s]' % cbo)

Then change the style of the scrollbar:

self.tk.eval(f'$popdown.f.sb configure -style my.TCombobox.Vertical.TScrollbar')

Full example:

import tkinter as tk
import tkinter.ttk as ttk

class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)
        self.title('Default Demo')
        self.geometry('420x200')

        style = ttk.Style()
        style.configure('my.TCombobox', arrowsize=30)
        style.configure('my.TCombobox.Vertical.TScrollbar', arrowsize=28)

        values = []
        for idx in range(1, 50):
            values.append(f'Testing-{idx}')

        cbo = ttk.Combobox(self, values=values, style='my.TCombobox')
        cbo.grid(ipady=5)

        self.tk.eval('set popdown [ttk::combobox::PopdownWindow %s]' % cbo)
        self.tk.eval(f'$popdown.f.sb configure -style my.TCombobox.Vertical.TScrollbar')

        ttk.Scrollbar(self, orient='vertical').grid(row=0, column=1, sticky='ns')

if __name__ == '__main__':
    app = App()
    app.mainloop()
j_4321
  • 15,431
  • 3
  • 34
  • 61