4

I'm making a simple game using python and Tkinter. All works well, but I can't seem to change the appearance of the only button in the game (a RESET button on the bottom). It should be flat and blue with white text, to match the rest of the layout. This is the code i'm using now:

resetbutton = Button(root, text='RESET', width=15, command=sw.Reset, highlightbackground="blue", relief='flat')
resetbutton.grid(column=5, columnspan=3, row=13, rowspan=1)

... but the button still looks like the default one. Anyone got any ideas why this doesn't work?

2 Answers2

1

You can do like below with fg and bg (you can also assign fonts [if supported]):

Button(root, text='RESET', command=sw.Reset, font='Arial -20 bold', relief='flat', bg='blue', fg='white', width=10, height=2)
Tanmaya Meher
  • 1,438
  • 2
  • 16
  • 27
  • I've used bg en fg succesfully for the labels, but for some reason it doesn't do anything with this button.. Also, the relief is still the same even though I use relief='flat' (which is correct syntax I think).. – Jonas Kiebooms Aug 16 '14 at 09:59
  • 1
    Are you on **Mac OS** ?! It had complains of not supporting backgrounds and foregrounds of Buttons in Tkinter. [Hopefully the Link will help](http://stackoverflow.com/questions/1529847/how-do-i-change-the-foreground-or-background-colour-of-a-tkinter-button-on-max-o) – Tanmaya Meher Aug 16 '14 at 10:03
  • That's right! Do you know a work around for this issue? I'm coding on a mac, but the game will be used for kids in a school and the school uses only windows so maybe I should just configure and test the button on a windows? – Jonas Kiebooms Aug 16 '14 at 10:05
  • Yeah ! Its working perfectly on both Windows and Linux. If you are going to run it in windows, then its perfectly fine. Just test your game once on Windows. Haven't found anything yet for Mac. – Tanmaya Meher Aug 16 '14 at 10:32
  • Even using `themedtk`, i.e., `ttk`, text color may work but background doesn't work on Mac. – Tanmaya Meher Aug 16 '14 at 10:41
  • Ok, thanks for your help! I'm gonna switch to a Windows computer now and once the button looks the way I want it, I'll continue the rest of the coding om my own mac :) – Jonas Kiebooms Aug 16 '14 at 10:48
0

The given answer is correct, however, if you hover the mouse upon the button, this later one will change both the blue and white colors to the default ones.

So to keep the same design when you hover the mouse, you can add these two options for your resetbutton button:

  • activebackground="blue"
  • activeforeground= "white"
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130