Label
来删除文本上方和下方的空格,因为高度对应于由字体大小决定的整数行数。 这种行高会为下降到基线以下的字母留出空间,例如 'g',但由于您不使用此类字母,因此在文本下方有大量空白空间(在我的计算机上顶部的额外空间并不多)。要删除此空格,可以使用Canvas
而不是Label
,并将其调整大小为较小的尺寸。import tkinter as tk
root = tk.Tk()
canvas = tk.Canvas(root, bg='green')
canvas.grid()
txtid = canvas.create_text(0, -15, text='20°C', fill='white', font=('Calibri', 140), anchor='nw')
# I used a negative y coordinate to reduce the top space since the `Canvas`
# is displaying only the positive y coordinates
bbox = canvas.bbox(txtid) # get text bounding box
canvas.configure(width=bbox[2], height=bbox[3] - 40) # reduce the height to cut the extra bottom space
root.mainloop()