[英]Python tkinter label background image
我想在 label 上放置背景圖像,但文本仍在顯示。
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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.