簡體   English   中英

Tkinter 標簽背景?

[英]Tkinter Label background?

我再次遇到了 Tkinter 的一些問題。

正如您在圖像中看到的,默認情況下標簽具有灰色背景。 現在我有一個標簽設置為背景,由於明顯的原因,我希望文本標簽中的灰色消失。 我怎樣才能使標簽的背景透明?

from Tkinter import *

# ***** Start of Gui *****
root = Tk()
root.title("Here could be your ad")
root.geometry("350x150")
root.minsize(350,150)
root.resizable(False, False)

# ***** Background *****
photo = PhotoImage(file="recycled.gif")
background_label = Label(root, image=photo)
background_label.place(x=0, y=0, relwidth=1, relheight=1)
background_label.image = photo

# ***** Text *****
l1 = Label(root, text="Here could be your ad")
l2 = Label(root, text="Here could be your ad")
l3 = Label(root, text="Here could be your ad")
l4 = Label(root, text="Here could be your ad")

l1.grid(row=0, sticky=W)
l2.grid(row=1, sticky=W)
l3.grid(row=2, sticky=W)
l4.grid(row=3, sticky=W)

# ***** Variables for Input *****
var0 = StringVar()
var1 = StringVar()
var2 = StringVar()
var3 = StringVar()

# ***** Input Boxes *****
e1 = Entry(root, textvariable=var0)
e2 = Entry(root, textvariable=var1)
e3 = Entry(root, textvariable=var2)
e4 = Entry(root, textvariable=var3)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)
e3.grid(row=2, column=1)
e4.grid(row=3, column=1)

#Button
b = Button(root, text="Here could be your ad", bg='blue')
b.grid(row=4, column=1)

root.mainloop()

你不能。 標簽不支持透明度。

最好的解決方案可能是使用畫布作為背景,並使用文本對象而不是標簽,因為文本對象只繪制文本而不是背景。

暫無
暫無

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

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