Home > Back-end >  Combobox changing out of focus background and foreground color
Combobox changing out of focus background and foreground color

Time:09-26

I need to change the foreground and background colour of combobox input field when it is not in focus. I read through these Picture

I would like to make the text as black with background as white.

CodePudding user response:

I was able to resolve this after reading this

Here is the updated code.

import tkinter as objTK
from tkinter import ttk as objTTK

objWindow = objTK.Tk()

objStyle = objTTK.Style()
objStyle.theme_use("clam")
objStyle.map("TCombobox", selectforeground=[('readonly', '!focus', 'black')], \
            selectbackground=[('readonly', '!focus', '#DCDAD5')])
tMonths = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
cbDtRStM = objTTK.Combobox(master=objWindow, width=10, state="readonly", values=tMonths)
cbDtRStM.pack()

btnButton = objTTK.Button(master=objWindow, text="Test")
btnButton.pack()

objWindow.bind("<Escape>", lambda funcWinSum: objWindow.destroy())

objWindow.mainloop()
  • Related