Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 689
lemiant Avatar asked Sep 13 '25 21:09

lemiant


2 Answers

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.

like image 113
Bryan Oakley Avatar answered Sep 16 '25 12:09

Bryan Oakley


This problem has been plaguing Macs for years. But as of Python 3.7 it's safe-ish to install from Python.org instead of Homebrew. This problem disappears when Python is installed from Python.org instead of running the Homebrew version.

like image 35
Mike from PSG Avatar answered Sep 16 '25 11:09

Mike from PSG