Python tkinter 标签背景图片
Python tkinter label background image
我想在标签上放置背景图片,但文本仍显示。
img = tk.Photoimage(file = "image.png")
tk.Label(root, text = "test", image = img).pack()
但是文本不显示。我认为它被图像覆盖了。
您需要使用 Label
的 compound
选项来说明如何将文本和图像放在一起:
tk.Label(root, text='test', image=img, compound='center')
会将文字放在图片的中央。
其他选项:
'left', 'top', 'right', 'bottom': put the image at the specified side of text.
我想在标签上放置背景图片,但文本仍显示。
img = tk.Photoimage(file = "image.png")
tk.Label(root, text = "test", image = img).pack()
但是文本不显示。我认为它被图像覆盖了。
您需要使用 Label
的 compound
选项来说明如何将文本和图像放在一起:
tk.Label(root, text='test', image=img, compound='center')
会将文字放在图片的中央。
其他选项:
'left', 'top', 'right', 'bottom': put the image at the specified side of text.