Transparent background in a Tkinter window Transparent background in a Tkinter window tkinter tkinter

Transparent background in a Tkinter window


It is possible, but it's OS-dependent. This will work in Windows:

import Tkinter as tk # Python 2import tkinter as tk # Python 3root = tk.Tk()# The image must be stored to Tk or it will be garbage collected.root.image = tk.PhotoImage(file='startup.gif')label = tk.Label(root, image=root.image, bg='white')root.overrideredirect(True)root.geometry("+250+250")root.lift()root.wm_attributes("-topmost", True)root.wm_attributes("-disabled", True)root.wm_attributes("-transparentcolor", "white")label.pack()label.mainloop()


Here is a solution for macOS:

import tkinter as tkroot = tk.Tk()# Hide the root window drag bar and close buttonroot.overrideredirect(True)# Make the root window always on toproot.wm_attributes("-topmost", True)# Turn off the window shadowroot.wm_attributes("-transparent", True)# Set the root window background color to a transparent colorroot.config(bg='systemTransparent')root.geometry("+300+300")# Store the PhotoImage to prevent early garbage collectionroot.image = tk.PhotoImage(file="photoshop-icon.gif")# Display the image on a labellabel = tk.Label(root, image=root.image)# Set the label background color to a transparent colorlabel.config(bg='systemTransparent')label.pack()root.mainloop()

Screenshot

(tested on macOS Sierra 10.12.21)


There is no cross-platform way to make just the background transparent in tkinter.