Tkinter button background color is not working in mac os
Question:
I am trying to change the bg color of a tkinter button on my mac (catalina) but instead of getting a colored background, it is showing a blank white space in the layout.
The button code I used:
button_open = Button(root, width=45, bg="#82CC6C", fg="black", text="OPEN",
highlightbackground="#82CC6C", highlightthickness=1,
borderwidth=0.2, relief="groove", padx=0, pady=0)
button_open.grid()
Result I am getting:
What I expected:
I tried changing all the parameters but it is always giving me the same result,
How can we fix this? Is it a bug in tkinter on mac only?
Answers:
I was looking for information on the same issue and it seems to be a limitation with tkinter using the MacOS APIs. Basically MacOS says the button colors can’t change so tkinter can’t change them.
I got the fix:
Use tkmacosx module for tkinter buttons in mac, use from tkmacosx import Button
and then change the parameters and also add this parameter borderless=1
to remove the unnecessary layout.
You can see the result I got after using this:
I am trying to change the bg color of a tkinter button on my mac (catalina) but instead of getting a colored background, it is showing a blank white space in the layout.
The button code I used:
button_open = Button(root, width=45, bg="#82CC6C", fg="black", text="OPEN",
highlightbackground="#82CC6C", highlightthickness=1,
borderwidth=0.2, relief="groove", padx=0, pady=0)
button_open.grid()
Result I am getting:
What I expected:
I tried changing all the parameters but it is always giving me the same result,
How can we fix this? Is it a bug in tkinter on mac only?
I was looking for information on the same issue and it seems to be a limitation with tkinter using the MacOS APIs. Basically MacOS says the button colors can’t change so tkinter can’t change them.
I got the fix:
Use tkmacosx module for tkinter buttons in mac, use from tkmacosx import Button
and then change the parameters and also add this parameter borderless=1
to remove the unnecessary layout.
You can see the result I got after using this: