1

After many attempts and google searches I can't figure out how to set a button's background colour. This what I have right now.

password_button = Button(window, text="SUBMIT", width=5, command=click, bg="black").grid(row=2, column=0, sticky=W)

Any help would be appreciated.

  • Possible duplicate of [How to change the foreground or background colour of a Tkinter Button on Mac OS X?](http://stackoverflow.com/questions/1529847/how-to-change-the-foreground-or-background-colour-of-a-tkinter-button-on-mac-os) – j_4321 May 07 '17 at 11:20
  • not a duplicate, I tried those solutions, and also that question was about python 2 not python 3 – BloodPanther May 07 '17 at 11:35
  • Then please edit the question to tell us what you have tried. In addition, I don't think the version of python really matters here. – j_4321 May 07 '17 at 11:56

1 Answers1

0

There are some errors with your code. First of all, you should either make the button first and then grid it, or you can directly grid it. In your code, you are making a variable called password_button, but at the end of it, you are trying to grid the button from inside the variable. To solve the problem, you can just move the grid command to a separate line like this:

password_button = Button(window,
                         text="SUBMIT",
                         width=5,
                         bg="black")
password_button.grid(row=2, column=0,sticky=W)

Second of all, I don't think that changing background colors of buttons in tk is possible, but you can use ttk widgets to change the background color of a button.

linkai
  • 18
  • 1
  • 7