How to create transparent widgets using Tkinter?

A Tkinter widget in an application can be provided with a transparent background. The background property of any widget is controlled by the widget itself.

However, to provide a transparent background to a particular widget, we have to use wm_attributes('-transparentcolor', 'colorname') method. It works in the widget only after adding the same transparent color as the background color of the widget.

How Transparent Widgets Work

The transparency effect works by defining a specific color that becomes transparent. Any widget using this exact color as its background will appear transparent, allowing you to see through to whatever is behind the window.

Example

Here's how to create a transparent label widget ?

#Import the required libraries
from tkinter import *

#Create an instance of Tkinter Frame
win = Tk()

#Set the geometry
win.geometry("700x250")

#Adding transparent background property
win.wm_attributes('-transparentcolor', '#ab23ff')

#Create a Label with the same transparent color
Label(win, text="This is a New line Text", font=('Helvetica', 18), bg='#ab23ff').pack(ipadx=50, ipady=50, padx=20)

win.mainloop()

When we compile the above code, it will display a window with a Label widget in transparent background.

Transparent Widget Window This is a New line Text (Transparent background)

Key Points

  • The transparent color must be set using wm_attributes('-transparentcolor', 'color')
  • Widgets must use the exact same color as their background to become transparent
  • This feature works on Windows and may have limited support on other platforms
  • The transparency affects the entire widget, not just parts of it

Alternative Approach with Multiple Widgets

You can create multiple transparent widgets by assigning the same transparent color ?

from tkinter import *

win = Tk()
win.geometry("600x300")

# Set transparent color
transparent_color = '#ff00ff'
win.wm_attributes('-transparentcolor', transparent_color)

# Multiple transparent widgets
Label(win, text="Transparent Label 1", bg=transparent_color, font=('Arial', 16)).pack(pady=20)
Label(win, text="Transparent Label 2", bg=transparent_color, font=('Arial', 14)).pack(pady=10)

# Non-transparent widget (different background color)
Label(win, text="Opaque Label", bg='white', font=('Arial', 12)).pack(pady=10)

win.mainloop()

Conclusion

Use wm_attributes('-transparentcolor', 'color') to make widgets transparent in Tkinter. Any widget with the matching background color will become transparent, allowing the desktop to show through.

Updated on: 2026-03-25T20:43:05+05:30

26K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements