29

I'm trying to change the background color of my Tkinter app, but for certain widgets it leaves a white border around the edges.

For example, this:

from tkinter import *

COLOR = "black"

root = Tk()
root.config(bg=COLOR)

button = Button(text="button", bg=COLOR)
button.pack(padx=5, pady=5)
entry = Entry(bg=COLOR, fg='white')
entry.pack(padx=5, pady=5)
text = Text(bg=COLOR, fg='white')
text.pack(padx=5, pady=5)

root.mainloop()

How can I set border colour of certain Tkinter widgets?

nbro
  • 12,226
  • 19
  • 85
  • 163
jefdaj
  • 1,817
  • 1
  • 19
  • 30

2 Answers2

45

Just use

widget.config(highlightbackground=COLOR)

Furthermore, if you don't want that border at all, set the highlightthickness attribute to 0 (zero).

nbro
  • 12,226
  • 19
  • 85
  • 163
jefdaj
  • 1,817
  • 1
  • 19
  • 30
  • 5
    I wish this nice solution worked for all widgets, but `Combobox` widgets, for example, don't have a `highlightbackground` option. So the solution applied to a combobox raises `tkinter.TclError: unknown option "-highlightbackground"`. – Victor Mar 25 '19 at 23:03
  • 9
    How is highlightbackground related with the border of the background, that it is supposed to work even if widget is not highlighted? – Marjan100 Nov 08 '19 at 08:42
1

You have to set the two highlights (with and without focus) to have a continuous color.

from tkinter import *
root = Tk()
e = Entry(highlightthickness=2)
e.config(highlightbackground = "red", highlightcolor= "red")
e.pack()
root.mainloop()