简体   繁体   English

(python, tkinter, ttk, style) 如何改变ttk.Button的整体颜色?

[英](python, tkinter, ttk, style) How to change the whole color of ttk.Button?

I am trying to make a button change the color.我想让一个按钮改变颜色。

Here is my code:这是我的代码:

 root = tk.Tk()
 style = ttk.Style()
 style.configure("test.TButton", background="white", foreground="white")
 test_btn = ttk.Button(root, style="test.TButton")
 test_btn.pack()
 root.mainloop()

I want to change the whole color of button.我想改变按钮的整体颜色。 but its ridge(or margin or little of little of part of button) has been changed.但它的脊线(或边缘或按钮的一小部分)已更改。

I tried same approach to change the color on "ttk.Label".我尝试了相同的方法来更改“ttk.Label”上的颜色。 it works perfect.它工作完美。 Is there a way to change the whole color of "ttk.Button"??有没有办法改变“ttk.Button”的整体颜色?

Specifially, I want to make a button with image and the other part of button transparent.具体来说,我想让一个带有图像的按钮和按钮的另一部分透明。 So, I want to match the other part with same color of background.所以,我想用相同颜色的背景匹配另一部分。

Answer To Your Question is- There Is Now Way To Style A ttk button,对你的问题的回答是——现在有办法设置一个ttk按钮的样式,

But You You Can Infinitely Style A Normal tk.Button like this-但是你可以无限地设计一个普通的tk.Button就像这样-

from tkinter import *

root = Tk()


test_btn = Button(root, text="YOUR TEXT IS HERE!", background='crimson', foreground='white', width=30, 
height=5, font=('Segoe UI', 40))
test_btn.pack()


root.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM