maq maq - 1 year ago 374
Python Question

How to change the color of ttk button

I am using Python 3.x on Windows.

My problem is I want to customize a button widget of

by completely changing its background and foreground color. But so far, I have been unsuccessful.

My desired button is:

enter image description here

I read the
guide and used their code:

ttk.Style().configure("TButton", padding=6, relief="flat",

btn = ttk.Button(text="Sample")

But it's changing the border color instead of the whole button bakground. Here is the output:

enter image description here

Kindly help me achieve my desired button.

Answer Source

Unfortunately, there isn't an easy way to change the foreground of a button from the ttk library. It is always the standard Windows gray like in your picture.

But you can easily get what you want with a normal tkinter.Button if you set the right options. Below is an example script:

import tkinter as tk

root = tk.Tk()
btn = tk.Button(root, 
                text='hello button',


And here is what it will look like:

enter image description here

Also, the shade of green I picked was just an example one that I thought was pretty close to what you wanted. But you can specify any hex color code you want. If you need to turn a RGB value into hex, a simple trick is to use str.format like so:

>>> rgb = (183, 247, 49)
>>> '#{:02x}{:02x}{:02x}'.format(*rgb)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download