How to change the foreground or background colour of a Tkinter Button on Mac OS X?
I think the answer is that the buttons on the mac simply don't support changing the background and foreground colors. As you've seen, this isn't unique to Tk.
Tkinter button background color is not working in mac os
I got the fix:
Use tkmacosx module for tkinter buttons in mac, use "from tkmacosx import Button", and then change the parameters and use borderless=1 to remove the unnecessary layout.
You can see the result I got after using the module:
tkinter python 3 how to set a buttons background colour on mac osx
There are some errors with your code. First of all, you should either make the button first and then grid it, or you can directly grid it. In your code, you are making a variable called password_button, but at the end of it, you are trying to grid the button from inside the variable. To solve the problem, you can just move the grid command to a separate line like this:
password_button = Button(window,
text="SUBMIT",
width=5,
bg="black")
password_button.grid(row=2, column=0,sticky=W)
Second of all, I don't think that changing background colors of buttons in tk is possible, but you can use ttk widgets to change the background color of a button.
Changing color of buttons in tkinter works on Windows but not Mac OSX
In this page of the tcl/tk wiki are listed some problems related to Mac and the color of labels and buttons's backgrounds. For example:
...
The Mac OS X background color should not be white, it should be #ececec. Since winfo rgb does not work properly on the mac colors, this makes it difficult to get the proper default color.
... etc.
Saludos!,
Tkinter Button background - white only on a mac (10.15.4)
There is a problem with tkinter and python 3.73. Works fine with Python 3.72 but not 3.73. I got this info about tkinter from the instructions for Simple_GUI,
Why am I not able to visualise background colours for buttons in Tkinter Python on a Mac?
I found the answer to this question at "How to change the foreground or background colour of a Tkinter Button on Mac OS X?"
just changing the command bg="color"
to highlightbackground="color"
works for me on a Mac OS.
How do I change background colour of a button on hover in Tkinter?
You can use <Enter>
and <Leave>
events to change the fg
and bg
color of the button:
import tkinter
window = tkinter.Tk()
button = tkinter.Button(window, text="Test", fg='#03045e', command=terminate_instant,
relief=tkinter.RIDGE, bg='#caf0f8', activebackground='#ef233c',
activeforeground='white')
button.pack(side=tkinter.BOTTOM)
button.bind("<Enter>", lambda e: button.config(fg='#caf0f8', bg='#03045e'))
button.bind("<Leave>", lambda e: button.config(fg='#03045e', bg='#caf0f8'))
window.mainloop()
How to change the foreground or background colour of a Tkinter Button on Mac OS X?
I think the answer is that the buttons on the mac simply don't support changing the background and foreground colors. As you've seen, this isn't unique to Tk.
Related Topics
How to Assign Values to a Numpy Array as a Function of Index
Python: How to Keep Repeating a Program Until a Specific Input Is Obtained
Concatenate Two Columns in Csv: Python
How to Make a List With All Possible Combinations
How to Call a Classes Method from Another Class Without Initialising the First Class
How to Remove a Pandas Dataframe from Another Dataframe
How to Update Sqlalchemy Orm Object by a Python Dict
Python Executable Not Finding Libpython Shared Library
How to Remove Grid Lines on Image in Python
Blender - How to Add a Color to an Object
How to Merge Json Objects Containing Arrays Using Python
Get Usb Device Address Through Python
How to Extract Data from Text Field in Pandas Dataframe
How to Strip Comma in Python String
Convenient Way to Handle Deeply Nested Dictionary in Python