首页 > 解决方案 > 如何动态更改 ttk 按钮字体颜色和背景

问题描述

我尝试了各种方法来做到这一点,但我错过了一些东西。在开始时,我认为我需要创建一种样式并将其分配给按钮

st = ttk.Style()
st.configure('blueTButton', foreground="white", background="blue")
Btn.configure(style='blueTButton')

但我收到一个错误:_tkinter.TclError: Layout blueTButton not found

所以我尝试了这个:

Btn.configure(foreground = 'red')
# and also
Btn.config(foreground = 'red')

以及许多其他愚蠢的尝试。

有人可以帮忙吗?

标签: pythontkinterttk

解决方案


推荐阅读