Button Mac OS

Posted on  by
Mojave

Question or issue on macOS:

  • A push button appears within a view and initiates an instantaneous app-specific action, such as printing a document or deleting a file. Push buttons contain text—not icons—and often open a separate window, dialog, or app so the user can complete a task. Configure a push button the user is likely to select as the default.
  • Before Mac OS X 10.10 (Yosemite), Mac OS usually provided three buttons for window interactions: Window controls in Mavericks The green button was used to “zoom” the window, meaning that the window would enlarge to display all the window content.

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:

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.

Next use place to parent a background color button on top of it. This will be the button with the 'command' on it or the button you bind events to. If you want your code to be OS independent, you can either add an 'if OS 'Mac' statement or even add a custom function that modifies the button if its on a Mac but leaves it alone on Windows.

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.

1) Open System Preferences → Keyboard 2) Click the Shortcuts tab 3) Click the “All controls” radio button Alternatively, you can use a simple keyboard shortcut—Control (⌃)+F7—to enable All controls to change keyboard focus when tabbing. A checkbox is a type of button that lets the user choose between two opposite states, actions, or values. A selected checkbox is considered on when it contains a checkmark and off when it's empty. A checkbox is almost always followed by a title unless it appears in a checklist. Provide a title that implies two opposite states.

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

How to solve this problem?

Solution no. 1:

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.

Solution no. 2:

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

Use:

For example:

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

Solution no. 3:

For anyone else who happens upon this question as I did, the solution is to use the ttk module, which is available by default on OS X 10.7. Unfortunately, setting the background color still doesn’t work out of the box, but text color does.

It requires a small change to the code:

Original:

With ttk:

Solution no. 4:

You can do it with tkmacosx from Pypi

Installation:-

for python2

for python3

Button Mac Os 11

Now use it:

Button Mac Os Download

It works fine on mac os x.

P.S For more information see it on Pypi

Solution no. 5:

Its quite annoying that after years this is still a problem.

Anyways, as others have mentioned, highlightbackground (the border color) can be used in place of background on a Mac. If you increase the size of the border to be huge (the size of the button or greater), you will get a nice, solid background color. This will give your button the appearance of a label.

Button Mac OS

This works if you are using place, but not if you are using something like grid. With grid, increasing the border size increases the button size automatically, unfortunately.

However, if you must use grid, you can always hack it….create your colorless grid button. Next use place to parent a background color button on top of it. This will be the button with the ‘command’ on it or the button you bind events to.

If you want your code to be OS independent, you can either add an ‘if OS “Mac”‘ statement or even add a custom function that modifies the button if its on a Mac but leaves it alone on Windows or Linux. Here’s the former:

Button Mascot

Solution no. 6:

This worked for me:

Solution no. 7:

I was looking as to why this doesn’t work as well. I found a quick way to try and fix it is to have a label and then bind a click with the label. Then have the label change colors for a short time to mimic clicking. Here is an example.

Solution no. 8:

Confirm following code can change the background of tkinter Button on Mac OS X.

But it cannot change bg of ttk.Button.

Hope this helps!