Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a tkinter Label background transparent?

I have a window with a label as my frame. I did this because i wanted an image in the background. But now im having trouble with the other labels i have used. The other labels i have used to actually labeled things dont have a transparent background. Is there a way to make the background of these labels transparent?

import Tkinter as tk

root = tk.Tk()
root.title('background image')

image1 = Tk.PhotoImage(file='image_name.gif')

# get the image size
w = image1.width()
h = image1.height()

# make the root window the size of the image
root.geometry("%dx%d" % (w, h))

# root has no image argument, so use a label as a panel
panel1 = tk.Label(root, image=image1)
panel1.pack(side='top', fill='both', expand='yes')

# put a button/label on the image panel to test it
label1 = tk.Label(panel1, text='here i am')
label1.pack(side=Top)

button2 = tk.Button(panel1, text='button2')
button2.pack(side='top')

# start the event loop
root.mainloop()
like image 851
Brandon Nadeau Avatar asked May 05 '12 10:05

Brandon Nadeau


People also ask

Can you clear a label in tkinter?

If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.

How do I make the background of text transparent?

In the Background Tools menu on the left tab column, click Background color. Click the Transparent checkbox underneath the color continuum. Your canvas is now transparent. Add your text to the canvas and adjust as desired.

How do I make a frame transparent in Python?

It is a standard Python interface to the Tk GUI toolkit shipped with Python. To create a transparent window, we will use the attributes() method. To create a transparent background, we need to use the -alpha argument in the attributes() method. The alpha is Used for transparency.

How do you change the color of a label in Python?

The attribute fg can be used to have the text in another colour and the attribute bg can be used to change the background colour of the label.


1 Answers

i think it can help, all black will be transparent

root.wm_attributes('-transparentcolor','black')
like image 87
lstdmi Avatar answered Oct 17 '22 00:10

lstdmi