Can't change color of button.ttk

33 Views Asked by At

The color of a button background doesn't change using tkinter.ttk

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

style = ttk.Style()
style.configure("TButton", foreground="blue", background="orange")

myButton = ttk.Button(text="Scrape", style="TButton")
myButton.grid()

root.mainloop()
1

There are 1 best solutions below

0
Karan Shishoo On

In ttk for some systems you cant use the default theme if you want to change the colour of your buttons. If you use something like -

import tkinter as tk
from tkinter import ttk 
root = tk.Tk()
style = ttk.Style()
style.theme_use('alt')

style.configure("TButton", foreground="blue", background="orange")
myButton = ttk.Button(text="Scrape", style="TButton") myButton.grid()
root.mainloop()

It should allow you to freely change button fore/backgrounds. It is a relativity known issue with ttk buttons that some default themes prevent alterations of colour and such (OSX's aqua default theme is the main offender)