Python tkinter标签背景图像



我想在标签上放一个背景图像,但文本仍在显示。

img = tk.Photoimage(file = "image.png")
tk.Label(root, text = "test", image = img).pack()

但文本不会显示。我想它被图片覆盖了。

您需要使用Labelcompound选项来告诉如何将文本和图像放在一起:

tk.Label(root, text='test', image=img, compound='center')

将文本置于图像的中心。

其他选项:

'left', 'top', 'right', 'bottom': put the image at the specified side of text.

最新更新