Python Forum
Make Label Text background (default color) transparent using tkinter in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Make Label Text background (default color) transparent using tkinter in python
In reference to the earlier question, I am able to put a background image in the frame but now the major issue is that Label text is displaying with default background which I need to make transparent.

As per other references question tk.Canvas is the best option but is there any other way to make the background of text transparent using tk.Label, I use root.wm_attributes option but is making the Text transparent but not the Background Right now My display looks like as mentioned in the attachment.

import tkinter as tk
from tkinter.filedialog import asksaveasfile
from tkinter import messagebox
from PIL import ImageTk, Image

class SampleApp(tk.Tk):
    def __init__(self):
        self._frame = None
        self.ard_stat = read_json(JSON_PATH)

    def switch_frame(self, frame_class):
        """Destroys current frame and replaces it with a new one."""
        new_frame = frame_class(self)
        if self._frame is not None:
        self._frame = new_frame

class StartPage(tk.Frame):
    def loopCap(self):
        with open(JSON_PATH) as json_file1:
   = json.load(json_file1)
        if['status'] == 'ACTIVE': #and (['RH_img']!= 'null' or['LH_img']!= 'null')
            a = self.text.set(['status'])
            b = self.text1.set(['RH_cnt'])
            c = self.text2.set(['LH_cnt'])
            d = self.text3.set(['barcode'])
            return self.text, self.text1, self.text2, self.text3,

    def next_save(self):
        new_string =['barcode']
        new_folder = os.path.join(DATA_PATH,new_string)
        if os.path.exists(new_folder):
            #print("Folder Already Exists If Condition")
            tk.messagebox.showinfo("Info", "Folder Already Exists")
            #print("Folder Already Exists")
            #tkMessageBox.showinfo("Info", "Folder Already Exists")
            #print("Make Directory Else Condition")
            json_dict = read_json(JSON_PATH)
            json_dict.update({"frontend_status": "True"})
            dump_to_json(json_dict, JSON_PATH)
            for i in range(0,len(data)):
                folder_name = os.path.join(DATA_PATH, new_string, data[i])
                files = [('All Files', '*.*'),
                         ('Python Files', '*.py'),
                         ('Text Document', '*.txt')]
                file = asksaveasfile(initialdir=folder_name, filetypes=files, defaultextension=files)
            json_dict = read_json(JSON_PATH)
            json_dict.update({"frontend_status": "False"})
            dump_to_json(json_dict, JSON_PATH)

            self.master.after(500, self.loopCap)

    def __init__(self, master):
        self.master.geometry("1000x700+%d+%d" % (((self.master.winfo_screenwidth() / 2.) - (1280 / 2.)), ((self.master.winfo_screenheight() / 2.) - (720 / 2.))))
        self.master.config(bg='powder blue')
        #myvar = self.master
        Frame1 = tk.Frame(self.master)
        Frame1.pack(side="bottom", fill="x", pady=10, anchor='w')
        Frame2 = tk.Frame(self.master)
        Frame2.pack(side="left", fill="both", pady=10, anchor='w', expand=True )
        photo = tk.PhotoImage(file="images/BG.jpg")
        label = tk.Label(Frame2, image=photo)
        label.image = photo, y=0)
        tk.Label(Frame2, text='  Decal Check  ', font=('arial', 25, 'bold'), bg='powder blue',
                 fg='black', anchor='w').grid(column=0,pady=2)

        b = tk.Button(Frame2, text="Add New Files", command= self.next_save)
        b.grid(row=11, column=1, pady=5, sticky='w')

        self.master.after(500, self.loopCap)

if __name__ == "__main__":
    app = SampleApp()
Suggestion will be very helpful

Attached Files

wxpython has a SetTransparent command. tkinter does not, but I found this which may be helpful:

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter destroy label inside labelFrame Nick_tkinter 2 110 Feb-24-2021, 03:31 AM
Last Post: deanhystad
  How to read text in kivy textinput or Label jadel440 1 237 Dec-29-2020, 10:47 AM
Last Post: joe_momma
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 445 Dec-10-2020, 07:48 PM
Last Post: Larz60+
Photo Tkinter TEXT background image _ShevaKadu 5 1,385 Nov-02-2020, 10:34 AM
Last Post: joe_momma
  tkinter: Image to Label Maryan 10 641 Oct-29-2020, 01:48 PM
Last Post: joe_momma
  Tkinter - How can I remove the background borders from ttk.Button? TurboC 4 1,423 Oct-18-2020, 10:58 AM
Last Post: TurboC
  Tkinter - How can I extend a label widget? TurboC 2 368 Oct-13-2020, 12:15 PM
Last Post: zazas321
  tkinter | Button color text on Click Maryan 2 442 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Tkinter - How can I change the default Notebook border color? TurboC 4 1,468 Oct-06-2020, 10:35 PM
Last Post: TurboC
  [Tkinter] Text Upload LearningLittlebyLittle 0 358 Sep-04-2020, 07:55 PM
Last Post: LearningLittlebyLittle

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020