简体   繁体   English

Python tkinter label背景图

[英]Python tkinter label background image

I want to put a background image on a label, but with the text still displaying.我想在 label 上放置背景图像,但文本仍在显示。

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

But the text doesn't display.但文字不显示。 I think it's covered by the image.我认为它被图像覆盖了。

You need to use compound option of Label to tell how to put the text and image together:您需要使用Labelcompound选项来告诉如何将文本和图像放在一起:

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

will put the text at the center of image.将文本放在图像的中心。

Other options:其他选项:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM