Search code examples
pythontkinterheadertreeview

Active background color to treeview header


How to set the active background color for the treeview heading. used the following code, background and foreground is working fine but active background is not working. please help me with this

ttk.Style().theme_use('default')
ttk.Style().configure("Treeview.Heading",font=("Calibri",12,'italic'),activebackground="#81C44C",background = "#0D94D2",foreground="White")

Solution

  • You need to use style.map to change the behavior:

    pressed_color = 'black'
    highlight_color='red'
    
    ttk.Style().map("Treeview.Heading",
                    background = [('pressed', '!focus', pressed_color),
                                  ('active', highlight_color),
                                  ('disabled', '#ffffff')])
    

    As a good source