1

I have six different buttons in the Tkinter GUI each having different colors. I am able to visualize them with anaconda on Windows 10. But I am not able to visualize those buttons with the same Anaconda-Navigator on a Mac OS. I am not able to figure out why?

The python code for the buttons is as follows:

b1 = Button(root, text="Elbow Method", command=plot_elbow, bg="green", fg="white").pack(side = LEFT)
b2 = Button(root, text="K-Means Clustering", command=plot_kmeans, bg="blue", fg="white").pack(side = LEFT)
b3 = Button(root, text="Batsmen who scored 4 or more Hundreds", command=plot_hundreds, bg="#D35400", fg="white").pack(side = LEFT)
b4 = Button(root, text="Runs Scored by Various Players", command=plot_runs, bg="#117A65", fg="white").pack(side = LEFT)
b5 = Button(root, text="Best Batsmen", command=plot_best_batsmen, bg="#34495E", fg="white").pack(side = LEFT)
b6 = Button(root, text="Stop", command=root.destroy, bg="red", fg="white").pack(side = BOTTOM)

My expected output is 6 buttons with each having different background colors. Whereas, it's displaying 6 buttons with all of them having white backgrounds no matter what color I use.

So, can anyone please help me in solving this issue?

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Vivek
  • 336
  • 2
  • 4
  • 18
  • On Mac you can't change background color of a button. But you can achieve that by making a custom button class from `Label` or `Canvas`. – Saad Apr 23 '19 at 03:55
  • @Saad, Why is this the case? Are you absolutely sure? When I put Label instead of Button I get the following error in Windows: `File "C:\Users\Vivek\Anaconda3\lib\tkinter\__init__.py", line 2299, in __init__ (widgetName, self._w) + extra + self._options(cnf)) TclError: unknown option "-command"` – Vivek Apr 23 '19 at 04:39
  • 1
    Vivek, you can't pass command in a label. What I meant was to make a custom class inherited from either `Label` or `Canvas` and then use `bind` method to call the function. I can post an answer if you don't understand still, [but first check this post](https://stackoverflow.com/questions/1529847/how-to-change-the-foreground-or-background-colour-of-a-tkinter-button-on-mac-os) – Saad Apr 23 '19 at 04:45
  • 1
    The reason you can't is simply because Apple doesn't allow it, so that applications on that platform retain a consistent look. – Bryan Oakley Apr 23 '19 at 13:18

1 Answers1

0

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.

Vivek
  • 336
  • 2
  • 4
  • 18