Jared
Jared

Reputation: 3892

Tkinter GUI Python background color

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?

Upvotes: 2

Views: 22165

Answers (3)

Bryan Oakley
Bryan Oakley

Reputation: 385950

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.

Upvotes: 0

JAB
JAB

Reputation: 21089

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.

Upvotes: 2

pmacd
pmacd

Reputation: 81

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()

Upvotes: 0

Related Questions