How to set the background color of a ttk.Combobox

前端 未结 2 662
花落未央
花落未央 2020-12-06 12:58

I have a problem to set background color for Combobox using tkinter ttk with \'vista\' theme (I\'m using Python 3). I\'ve tried code from here ttk.Combobox glitch when state

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 13:22

    This code below worked fine for me.It is important set the order of the parameters.

    `

        style = ttk.Style()
    
        style.map('TCombobox', fieldbackground=[('readonly','white')])
        style.map('TCombobox', selectbackground=[('readonly', 'white')])
        style.map('TCombobox', selectforeground=[('readonly', 'black')])
    
        self.mycombo = ttk.Combobox(self.frame,textvariable=self.combo_var,
                                    height=15,justify='left',width=21,
                                    values=lista)
    
        self.mycombo['state'] = 'readonly' # Set the state according to configure colors
        self.mycombo.bind('<>',
                          lambda event: self._click_combo())
    

    `

提交回复
热议问题