0

I am currently trying to learn ttk themed widgets. I wanted to change the background colour of my ttk button. I followed to ttk docs and written this:

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()

in 'C.TButton' styling I tried to change the background colour of the 'btn1', but it only changes border colour to blue and not the background colour. How can I change the background colour?

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46
MegaLegend
  • 54
  • 7
  • No, there is no way to change the background color of a `ttk.Button` but you can always use a `tk.Button` like `tk.Button(backframe, text="Click me" , background="blue", relief="raised")`, but keep in mind your imports are pretty screwed up, make it like `import tkinter as tk` and `from tkinter import ttk` and prefix each widget with `ttk.` if you want to use a `ttk` widget, like `ttk.Button`. – Delrius Euphoria Nov 06 '20 at 09:31
  • @CoolCloud If using another theme, like `alt`, the background color can be changed. – acw1668 Nov 06 '20 at 10:44
  • @acw1668 Yes indeed, if your looking for a different theme, then ('clam', 'alt', 'default', 'classic') can be used whose background can be changed. – Delrius Euphoria Nov 06 '20 at 11:02
  • @acw1668 can you tell me how to change the theme. I'm a newbie. So if you can provide some code, that will be awesome – MegaLegend Nov 12 '20 at 12:32
  • Try adding `Style().theme_use('default')` before `Style().configyre(...)`. – acw1668 Nov 12 '20 at 12:50

0 Answers0