Python 如何动态更改ttk按钮字体颜色和背景

Python 如何动态更改ttk按钮字体颜色和背景,python,tkinter,ttk,Python,Tkinter,Ttk,我尝试过各种方法,但我错过了一些东西。 在Begging中,我认为我需要创建一个样式,然后将其指定给按钮 st = ttk.Style() st.configure('blueTButton', foreground="white", background="blue") Btn.configure(style='blueTButton') 但我得到了一个错误:\ tkinter.TclError:未找到布局blueTButton 所以我试了一下: Btn.configure(foregrou

我尝试过各种方法,但我错过了一些东西。 在Begging中,我认为我需要创建一个样式,然后将其指定给按钮

st = ttk.Style()
st.configure('blueTButton', foreground="white", background="blue")
Btn.configure(style='blueTButton')
但我得到了一个错误:\ tkinter.TclError:未找到布局blueTButton

所以我试了一下:

Btn.configure(foreground = 'red')
# and also
Btn.config(foreground = 'red')
还有许多其他愚蠢的尝试


有人能帮忙吗?

这能回答您的问题吗?这不是动态更改的。在创建时将样式添加到按钮是清晰的,但与鼠标单击“在创建时将样式添加到按钮是清晰的”时不同:您的“\u tkinter.TclError:Layout blueTButton not found”告诉其他人。