组合框改变焦点背景和前景色

Combobox changing out of focus background and foreground color

我需要在未获得焦点时更改组合框输入字段的前景色和背景色。我通读了这些 this and this 但无法弄清楚该使用哪一个。

我在 Windows 10 上使用 Python 3.9.6。

这是示例代码。

import tkinter as objTK
from tkinter import ttk as objTTK

objWindow = objTK.Tk()

objStyle = objTTK.Style()
objStyle.theme_use("clam")
objStyle.configure("TCombobox", backgroundcolor="orange")
objStyle.configure("TCombobox", foregroundcolor="blue")

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()

目前文字显示为灰色,如下图。

我想把文字设为黑色,背景设为白色。

我在阅读 this

后解决了这个问题

这是更新后的代码。

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()