2
votes

I'm writing a Tkinter application with buttons, graphs, sliders, etc, but I can't get their background color to be uniform.

import Tkinter
from Tkinter import *
root = Tk()
root.title('Button')
root.configure(bg='gray')

Button(text='Button', bg='gray').pack(side=BOTTOM)
root.mainloop()

If you run this code, the background of the main window is indeed gray, but the image of the button has a white area around it. Is there a way to fix this?

3
does borderwidth=0 help at all? - mgilson
I'm not sure what is causing your issue, because when I execute the code myself I don't get any "white area" around the button. I get a bit of white on the top and left, but that's due to the relief setting of the button. - JAB
Wow, looking back at old posts and seeing people import the same thing twice in 1 script - user5416120

3 Answers

2
votes

If the issue is that you don't like the default button effect on your system, you don't have to change the border width; instead you can set relief='flat' in the button declaration. That way, you'll still get the "sunken" look when you click the button, which you won't get if you just set borderwidth to 0 or a value close to it. Another issue with lessening borderwidth is that it may make the button smaller than expected.

0
votes

Expanding on mgilson's comment, I tried using borderwidth=.001 and as far as I could tell it 'effectively' removed the border on your button. Hope this helps!

import Tkinter
from Tkinter import *
root =Tk()
root.title('Button')
root.configure(bg='gray')

Button(text='Button',bg='gray',borderwidth=.001).pack(side=BOTTOM)
root.mainloop()
0
votes

What you are seeing sounds like the result of highlightthickness being set to a non-zero value (which is the default). You might try setting it to zero, or setting highlightbackground to your background color.