TKinter 在小部件周围留下边框 [英] TKinter leaving borders around widgets

查看:73
本文介绍了TKinter 在小部件周围留下边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在彩色背景上放置一个按钮时,TKinter 会在小部件周围留下这个奇怪的白色框.例如下面的代码:

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

我能做些什么来摆脱空白?

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

推荐答案

额外的边框是由 highlightthickness 属性引起的.默认值为 1(一);将其设置为零以删除边框.此边框显示按钮何时具有键盘焦点.

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.

但是,您似乎在 OSX 上运行它.与其他平台相比,OSX 按钮的可配置性稍差.将 highlightthickness 设置为零无济于事.您能做的最好的事情是将 highlightbackground 设置为与背景相同的颜色,以便融合.

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.

这篇关于TKinter 在小部件周围留下边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆