如何在Python';中更改按钮的颜色;斯特金特酒店

如何在Python';中更改按钮的颜色;斯特金特酒店,python,python-3.x,user-interface,tkinter,Python,Python 3.x,User Interface,Tkinter,我正在编写一个gui,我想更改按钮的颜色,但背景似乎改变了大纲的颜色,而不是整个背景的颜色。如何更改按钮背景的颜色 我试过背景和风格 salmon = "#FFC6AB" black = "#0C120C" # ADDING BUTTONS # Adding style style = ttk.Style() style.configure("X.TFrame", background=grey) style. configure("X.TButton", background=salmon,

我正在编写一个gui,我想更改按钮的颜色,但背景似乎改变了大纲的颜色,而不是整个背景的颜色。如何更改按钮背景的颜色

我试过背景和风格

salmon = "#FFC6AB"
black = "#0C120C"

# ADDING BUTTONS
# Adding style
style = ttk.Style()
style.configure("X.TFrame", background=grey)
style. configure("X.TButton", background=salmon, foreground=black, font=("Courier", 20), width=17)

# Adding spacer
spacer_1 = ttk.Frame(root)
spacer_1.grid(column=0, row=1, pady=12)
spacer_1.configure(style="X.TFrame")

# Adding frame
frame_2 = ttk.Frame(root)
frame_2.grid(column=0, row=2)
frame_2.configure(style="X.TFrame")

# Adding button 1
button_1 = ttk.Button(frame_2, text="Scale Cookbook")
button_1.grid(column=0, row=0)
button_1.configure(style="X.TButton")

您的做法是正确的,您的代码确实会在Linux中更改按钮的颜色。你不会得到你想要的结果,因为Windows和Mac默认的ttk主题不允许改变按钮的背景色(我想是因为它们是从图像创建的)

如果要更改按钮背景色,可以更改允许的主题,如“clam”或“alt”:

style = ttk.Style()
style.theme_use('clam')
# ... the rest of your style configuration