在python中更改ttk主题小部件的背景

问题描述

我目前正在尝试学习ttk主题的小部件。我想更改“ TTK”按钮的背景颜色。我遵循了ttk docs并编写了此代码

from tkinter import *
from tkinter.ttk import *

root = Tk()
root.title("GUI App One")
root.geometry("800x500")
root.maxsize(800,500)
root.minsize(800,500)

Style().configure("C.TButton",padding=6,background="blue",relief="raised")
Style().configure("B.TButton",font=("Arial",30))
Style().configure("Elem.TFrame",background="red")

backframe = Frame(root,width=800,height=500,style="Elem.TFrame")
backframe.place(x=0,y=0)
print()

btn1 = Button(backframe,text="Click me",style="C.TButton")
btn1.place(x=20,y=50)

btn2 = Button(backframe,text="Click me too",style="B.TButton")
btn2.place(x=100,y=100)

mainloop()

在'C.TButton'样式中,我尝试更改'btn1'的背景颜色,但它仅将边框颜色更改为蓝色,而不是背景颜色。如何更改背景颜色?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)