0

I know this is a common SO question, but I must be overlooking something very simple:

from tkinter import Tk,Button
root = Tk()  
root.geometry('100x50')  

button = Button(root, bg='blue',text = 'Submit' )
button.pack()

root.mainloop()

The button background simply will not change from default gray. On Mac with Monterey 12.5.1

fishbacp
  • 1,123
  • 3
  • 14
  • 29
  • 4
    Does this answer your question? [How to change the foreground or background colour of a Tkinter Button on Mac OS X?](https://stackoverflow.com/questions/1529847/how-to-change-the-foreground-or-background-colour-of-a-tkinter-button-on-mac-os) That was the first Google result. – TheLizzard Sep 11 '22 at 13:31
  • No, that doesn't seem to change the actual button color itself. There was a link on that post to info about a separate package for Mac: tkmacosx – fishbacp Sep 11 '22 at 13:37
  • I get the correct button color using tkmacosx, but I find it strange that I had to install a new package. – fishbacp Sep 11 '22 at 13:40
  • 2
    The question I linked, is the same as your question and the accepted answer says it's not possible with pure `tkinter`, that is why you had to download another package. For more info on how the other package works, look at its source code. – TheLizzard Sep 11 '22 at 13:42

1 Answers1

0

According to the documentation, color words work if they are also found in the rgb.txt file.

enter image description here

Out of curiosity, do other common colors work? Like red, blue, green? Or nothing works?

AlanSTACK
  • 5,525
  • 3
  • 40
  • 99
  • Are you sure that that applies to MacOS as well? If so, doesn't that make [this](https://stackoverflow.com/a/1530913/11106801) answer invalid? – TheLizzard Sep 11 '22 at 14:20
  • @TheLizzard That's interesting... I didn't know `tkinter` leveraged platform specific UI calls. I always assumed they did it themselves considering how awful it usually looks... – AlanSTACK Sep 11 '22 at 14:31
  • `tkinter` uses the `tcl/tk` library, which is very-very old (nearly as old as C++). Also it's always easier to use OS calls when creating these widgets then creating them from scratch. – TheLizzard Sep 11 '22 at 14:39