tenshi
tenshi

Reputation: 618

Setting background color or bg for a button in Python Tkinter not working

I'm new to tkinter and I can't set the background color of a button

My code:

from tkinter import *
from tkinter import ttk

root = Tk()
frame = Frame(root).grid(row = 0, column = 0)

button = ttk.Button(frame, text = "CLICK ME", bg = '#05752a').grid(row = 0, column = 0)

root.mainloop()

ERROR:

_tkinter.TclError: unknown option "-bg"     

Upvotes: 1

Views: 1679

Answers (1)

Sharim09
Sharim09

Reputation: 6214

Unfortunately, there isn't an easy way to change the background of a button from the ttk library.

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

from tkinter import *
from tkinter import ttk

root = Tk()
frame = Frame(root).grid(row = 0, column = 0)

button = Button(frame, text = "CLICK ME", bg = '#05752a').grid(row = 0, column = 0)

root.mainloop()

This is the Link to another post

Upvotes: 1

Related Questions