首页 > 解决方案 > 无法删除 1px 白色条带 - 即使添加了高光厚度?

问题描述

我遵循了这个例子,因为我在删除白色边框时遇到了问题。

OP 被告知要添加 highlightthickness 并将 x0、y0 和 y1 更改为 0。除了 1 px 的空白/行之外,这一切都有效吗?有任何想法吗?谢谢。

from tkinter import *

master = Tk()
master.configure(bg='#333333')
master.wm_attributes("-topmost", 1)
TopLevel.overrideredirect(True)

w = Canvas(master, width=150, height=40, bd=0, highlightthickness=0, relief='ridge',)
w.config()
w.pack(fill='both')

color = 100
x0 = 0
y0 = 0
x1 = 150
y1 = 0

while y0 < 20 :
    r = color
    g = color
    b = color
    rgb = r, g, b
    Hex = '#%02x%02x%02x' % rgb
    w.create_line(x0, y0, x1, y1,fill=str(Hex), width=1)
    color = color - 2
    y0 = y0 + 1
    y1 = y1 + 1

color = 10

while y0 < 40 :
    r = color
    g = color
    b = color
    rgb = r, g, b
    Hex = '#%02x%02x%02x' % rgb
    w.create_line(x0, y0, x1, y1,fill=str(Hex), width=1)
    color = color + 4
    y0 = y0 + 1
    y1 = y1 + 1

mainloop()

小的剩余白色边框

标签: python-3.xtkinterborder

解决方案


我更改了 4. 和 7. 行,因为 PyCharm 给了我一个错误:

from tkinter import *

master = Tk()
tl = Toplevel() # delete me if the issue still remains :)
master.configure(bg='#333333')
master.wm_attributes("-topmost", 1)
tl.overrideredirect(True) # delete me if the issue still remains :)
...

如果问题仍然存在,请尝试删除 4. 和 7. 行。不应该有任何问题


推荐阅读