Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Can I Change The Background Color Of A Button Using Tkinter On MacOs Big Sur [duplicate]

I've been working through the Tkinter chapters in Programming Python and encountered a problem where the foreground and background colours of a button will not change. I am working on a Mac OS X 10.6 system with Python 2.6.1. The colours of a label will change, but not the colours of a button. For example:

from Tkinter import *

Label(None, text='label', fg='green', bg='black').pack()
Button(None, text='button', fg='green', bg='black').pack()

mainloop()

On my Mac system the colours of the label change, but the colours of the button do not. On a Windows system with Python 2.6.1 the colours of both the label and button change.

Anyone know what is going wrong?

I've checked Interface Builder and it appears that there is no option to change the foreground or background colour of a button in that tool. There is the ability to edit the foreground and background colours of a label.

The Mac OS X rendering system (Quartz?) may just not support (easily) changing the fg and bg of a button.

like image 285
Anthony Cramp Avatar asked Feb 03 '26 12:02

Anthony Cramp


2 Answers

There is a solution for changing the background of buttons on Mac.

Use:

highlightbackground=color

For example:

submit = Button(root, text="Generate", highlightbackground='#3E4149')

This results in the following, a nice button that fits in with the background:

Button

like image 56
Luka Kerr Avatar answered Feb 05 '26 03:02

Luka Kerr


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.

like image 27
Bryan Oakley Avatar answered Feb 05 '26 03:02

Bryan Oakley