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()
If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.
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.
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.
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.
i think it can help, all black will be transparent
root.wm_attributes('-transparentcolor','black')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With