def __init__(self, master, text, foreground="black", truetype_font=None, font_path=None, family=None, size=None, **kwargs):
if truetype_font is None:
if font_path is None:
raise ValueError("Font path can't be None")
# Initialize font
truetype_font = ImageFont.truetype(font_path, size)
width, height = truetype_font.getsize(text)
image = Image.new("RGBA", (width, height), color=(0,0,0,0))
draw = ImageDraw.Draw(image)
draw.text((0, 0), text, font=truetype_font, fill=foreground)
self._photoimage = ImageTk.PhotoImage(image)
Label.__init__(self, master, image=self._photoimage, **kwargs)
评论列表
文章目录