3

Expected Behavior

I should get an output like this:

Observed behavior

What I got:

The Code

from tkinter import *

root = Tk()


def my_click():
    my_label = Label(root, text='Look! I clicked a button!')
    my_label.pack()


my_button = Button(root, text='Click Me!', command=my_click, bg='#6d35e6', fg='#0000ff')
my_button.pack()

root.mainloop()

Update On The Code

I'm using an attribute called highlightbackground instead of bg for the background. You can check the comment that I made for further details.

Version Info

System Os: MacOs Big Sur 11.3 (LTS)
Python Version: 3.9.4 (LTS)
Tkniter Version: 8.6 (LTS)
Code Editor: PyCharm CE Community 2021.1.1 (LTS)
Code With Anish
  • 95
  • 1
  • 1
  • 12
  • Just saying that on `Windows 10` + `tcl 8.6`, I get a purple button with blue text inside it. So the problem must come from MacOS. – TheLizzard Apr 30 '21 at 19:55
  • @TheLizzard Yeah, I know that. I'm just asking about MacOs. – Code With Anish Apr 30 '21 at 19:57
  • Have you tried using `"purple"` instead of `"#6d35e6"`? It might work but I don't own any devises that have MacOS – TheLizzard Apr 30 '21 at 19:58
  • 1
    I too don't use Mac. Can someone test who uses mac? Also thank you for your detailed question. – Tkinter Lover Apr 30 '21 at 20:01
  • 2
    You can't change the colors of buttons on OSX. – Bryan Oakley Apr 30 '21 at 20:05
  • @BryanOakley Are they fully controlled by the OS? Do you mind writing an answer. I am very interested by this question – TheLizzard Apr 30 '21 at 20:10
  • @TheLizzard Whenever I do that I get something like this: https://gist.github.com/CodeWithAnish/9992032c922c274fb636bf66bb4cd7ee (I sent a link to GitHub since I didn't know how to attach an image. You'll find the image in the comments btw.) – Code With Anish Apr 30 '21 at 20:25
  • **Update** I actually hound an attribute called "highlightbackground" which did change the background color but as soon as I press the button or moved the window around it would look something like this: [Link To The Image](https://gist.github.com/CodeWithAnish/9992032c922c274fb636bf66bb4cd7ee) (You'll find the image in the comments) – Code With Anish Apr 30 '21 at 21:39
  • @CodeWithAnish have you tried setting `activebackground`? If that doesn't work why setting `highlightcolor` – TheLizzard Apr 30 '21 at 21:50
  • @TheLizzard I tried that and it just removed the background entirely, I think that might not be a parameter option. – Code With Anish Apr 30 '21 at 21:54
  • 1
    If you really want to change the colour of the button on macOS and can use an external library then you can try [tkmacosx](https://pypi.org/project/tkmacosx/). – Saad Apr 30 '21 at 23:42
  • @Saad **THANKS ALOT** I read the documentation and it worked flawlessly. Thanks! – Code With Anish May 01 '21 at 00:34

0 Answers0