Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tkinter Label background?

Tags:

python

tkinter

I yet again have some problem with Tkinter.

As you can see in the image, the labels are having a grey background by default. Now that i have a label set as background i'd like to have the gray gone from the text labels because of obvious reasons. How can i manage to get the background of labels transparent?

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()
like image 578
Johnny Avatar asked Jun 07 '26 16:06

Johnny


1 Answers

You can't. Labels don't support transparency.

The best solution is probably to use a canvas for the background, and use text objects instead of labels since text objects only draw the text and not the background.

like image 158
Bryan Oakley Avatar answered Jun 09 '26 04:06

Bryan Oakley