Python Tkinter 如何删除框架周围的边框? [英] Python Tkinter How to remove the border around a Frame?

查看:47
本文介绍了Python Tkinter 如何删除框架周围的边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含多个框架的程序.一切正常,但我无法弄清楚为什么其中一个框架周围存在边框.

I have a program with several frames. Everything works well however I cannot figure out why the border around one of the frames exist.

我尝试了一些东西.

这是我的框架是如何创建的:

Here is how my frame is created:

kwListFrame = Frame(root)
kwListFrame.grid(row = 1, column = 0, rowspan = 1, columnspan = 1, sticky = N+S+E+W)
kwListFrame.columnconfigure(0, weight=1)
kwBGimage = Label(kwListFrame, image= baseBGimage)
kwBGimage.image = baseBGimage
kwBGimage.place(x = 0, y = 0)
kwBGimage.config(image = baseBGimage)

我试图改变:

kwListFrame = Frame(root)

致:

kwListFrame = Frame(root, highlightthickness=0)
#or
kwListFrame = Frame(root, padx=0, pady=0)
#or
kwListFrame = Frame(root, bd=0)

在那之后我试过了:

kwListFrame = Frame(root, highlightbackground= "some color that matches frame")

我什至试图将浮雕设置为平坦,即使我知道它的默认值是平坦的.

I even tried to set the relief to flat even thought I know its default value is flat.

因为我发现了几个关于在画布上去除边框的参考资料,所以我没有找到任何与 Frames 直接相关的内容.所以我可能使用了 highlightthicknesshighlightbackground 错误,但它没有抛出错误,所以它看起来应该可以解决问题.

As I have found several references to removing the border on canvas, I have not found anything related to Frames directly. So I may be using the highlightthickness and highlightbackground wrong but it did not throw an error so it seams like it should do the trick.

这是框架在顶部显示细边框的方式的图像.

Here is an image of the way the frame displays a thin border at the top.

我不确定为什么会出现这个问题.是因为我用的是图片作为背景吗?

I am not sure why the problem exist. Is it because I am using an image as the background?

我不想在这里发布我所有的代码,因为它会太多但是如果你想看到完整的代码我的程序在 Github

I did not want to post all my code here because it would be to much but if you want to see the full code my program is on Github

推荐答案

第一步是将bothborderwidthhighlightthickness设置为零.一个框架有两个类似边框的对象:实际边框和高光环".后者用于显示帧有焦点.

The first step is to set both the borderwidth and highlightthickness to zero. A frame has two border-like objects: the actual border and a "highlight ring". The latter is for showing that a frame has focus.

一旦你这样做,框架将没有边框.如果小部件周围仍然有某种类似边框的环,这可能是由于应用于几何管理器的填充,而您看到的是来自父窗口的颜色.

Once you do that, the frame will not have a border. If there's still some sort of border-like ring around the widget it is likely due to padding applied to the geometry manager, and what you are seeing is the color from the parent window.

在您的特定情况下,由于您将标签放入框架中,因此您也需要关闭标签的边框.您很可能看到的是标签的边框,而不是框架的边框.

In your specific case, since you are putting a label in the frame you need to turn the border of the label off, too. Most likely you are seeing the border of the label rather than the border of the frame.

我不能再具体了,因为您没有提供说明问题的最小但完全有效的示例.

I can't be any more specific since you didn't provide a minimal but otherwise fully working example that illustrates the problem.

这篇关于Python Tkinter 如何删除框架周围的边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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