簡體   English   中英

Python tkinter label背景圖

[英]Python tkinter label background image

我想在 label 上放置背景圖像,但文本仍在顯示。

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.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM