无法使用 a 删除文本上方和下方的空格,Label
因为高度对应于整数行,其高度由字体大小决定。此行高为低于基线的字母保留空间,例如“g”,但由于您不使用此类字母,因此文本下方有很多空白空间(我没有顶部的额外空间虽然在我的电脑上)。
要删除此空间,您可以使用 aCanvas
而不是 aLabel
并将其调整为更小。
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()
