如何删除字体的白色边框?

2024-09-28 03:15:47 发布

您现在位置:Python中文网/ 问答频道 /正文

如果我将字体族更改为fixedsys,白色边框确实会消失,但为什么 这是我的密码

import tkinter as tk

win = tk.Tk()

win.wm_attributes("-transparentcolor", "white")
win.configure(background='white')
label = tk.Label(text='Hello World', bg='white', font=('Microsoft YaHei', 30))
label.pack()
win.mainloop()

Tags: import密码tkinteras字体winlabeltk
1条回答
网友
1楼 · 发布于 2024-09-28 03:15:47

tkinker(和PIL)字体引擎对背景颜色进行抗锯齿处理,在您的案例中为“白色”。你在chars周围看到的不是真正的白色而是灰色。要最小化效果,应在前景附近选择背景色,例如,如果前景为“黑色”,则选择“灰色1”,然后使“灰色1”透明。当然你失去了抗锯齿效果,但是白色消失了。试试这个:

import tkinter as tk
win = tk.Tk()
trasp = 'gray1'
win.wm_attributes("-transparentcolor", trasp)
win.configure(background=trasp)
label = tk.Label(text='Hello world', fg='black', bg=trasp, font=('Microsoft YaHei', 30))
label.pack()
win.mainloop()
exit()

相关问题 更多 >

    热门问题