Search code examples
pythonpython-2.7user-interfacetkintertk-toolkit

TKinter leaving borders around widgets


When I put a button in on a colored background TKinter leaves this weird white box around the widget. For example the code below:

from Tkinter import *

root = Tk()
root.geometry("300x100+300+300")
root.configure(bg="red")
button = Button(root, text="Connect", highlightthickness=0)
button.pack()

root.mainloop()  

enter image description here

What can I do to get rid of the white spacing?


Solution

  • The extra border is caused by the highlightthickness attribute. The default value is 1 (one); set it to zero to remove the border. This border shows when the button has keyboard focus.

    However, it appears you're running this on OSX. OSX buttons are a bit less configurable than on other platforms. Setting highlightthickness to zero won't help. The best you can do is set highlightbackground to the same color as your background so that it blends in.