Reputation: 1303
I'm making a small little test software using Tkinter. I'm trying to color a button red, and when you click on it, it turns green.
There seem to be similar questions asked, but none of them made any difference.
root = tkinter.Tk()
root.title('Test Software')
root.resizable(width = False, height = False)
root.geometry("300x300")
HandleBarButton = ttk.Button(text = "Handle Bars", bg = "red", command = handleBarCommand)
HandleBarButton.grid(row = 0, column = 0)
parkingStallButton = ttk.Button(text = "Parking Stalls", bg = "red", command = parkingStallsCommand)
parkingStallButton.grid(row = 0, column = 1)
toiletButton = ttk.Button(text = "Toilets", bg = "red", command = toiletsCommand)
toiletButton.grid(row = 0, column = 2)
doorsButton = ttk.Button(text = "Doors", bg = "red", command = doorsCommand)
doorsButton.grid(row = 0, column = 3)
I have commands defined above, but It's not essential to my question. When I run this, it gives the error :
_tkinter.TclError: unknown option "-bg"
Any help on this? Thanks.
Upvotes: 1
Views: 2181
Reputation: 3734
That is because bg option is not supported in ttk button constructor.You can change the background color easily if you use a normal tkinter button.
HandleBarButton= tkinter.Button(root,text = "Handle Bars", bg = "red", command = handleBarCommand)
or if really want to use ttk buttons,you can try changing the style database using,
ttk.Style().configure("TButton", padding=6, relief="flat",background="red")
HandleBarButton = ttk.Button(text = "Handle Bars", bg = "red", command = handleBarCommand)
But the second method may not give you the desired result.
Upvotes: 4