0

If I change the font family to fixedsys, it's true that the white border disappears, but why? Here is my code

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()
  • 1
    I don't think that is possible. Try a different font maybe? – TheLizzard Mar 23 '21 at 08:24
  • 2
    Different font are made up in a different way? Maybe the previous font has traces of white in its border and those have trouble getting removed. – Delrius Euphoria Mar 23 '21 at 08:32
  • 1
    @CoolCloud if this would be true, you would see the white gaps even by changing the backgroundcolor. If OP just want a line of text, I would recommend to draw text via PIL, it should do the trick. As a [reference](https://stackoverflow.com/a/61747128/13629335) – Thingamabobs Mar 23 '21 at 09:53

1 Answers1

0

The tkinker (and PIL) font engine makes antialiasing against the color of background, 'white' in your case. What you see around chars is not really white but gray. To minimize the effect you should select a background color near the foreground, for example 'gray1' if the foreground is 'black', and then make the 'gray1' transparent. Surely you loose antialiasing effect but the white is gone. Try this:

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()
hussic
  • 1,816
  • 9
  • 10