Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to create transparent windows with Tkinter?

Tags:

I'm trying, ultimately, to create "oddly-shaped windows" with Python using the Tkinter module. But for now I will settle for being able to make the background transparent while keeping child widgets fully-visible.

I'm aware this is done with wxPython and some other modules, but I'm inquiring as to the limits of Tkinter.

Can Tkinter create a clear Canvas or Frame? Can it pack UI elements without a canvas or frame? Can individual UI elements be transparent?

Can it pass mouse-click locations back to the system for processing any windows below it in the Z stack?

like image 664
Paul Johnson Avatar asked Aug 23 '13 04:08

Paul Johnson


People also ask

How do you make a transparent background in Tkinter?

A Tkinter widget in an application can be provided with 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.

Can you make a canvas transparent Tkinter?

Build A Paint Program With TKinter and Python If we want to create a transparent window in an application, then we should have to define the color in the attributes('-transparentcolor', 'color' ) method. By providing the color of the window and widget, it will make the window transparent.

Is Tkinter good for GUI?

Tkinter is the standard built-in GUI library for Python, and, with over 41,000 stars on GitHub, it's the most popular Python GUI framework. It's a fast and easy-to-use Python GUI library, making it the go-to library for building a Python GUI application.


1 Answers

The option root.attributes('-alpha', 0.1) can be used to make a transparent window

from Tkinter import *
root = Tk()
root.attributes('-alpha', 0.3)
root.mainloop()

However in this case even the widgets on the root will inherit the transparency.

Update for Linux (Tested on Ubuntu)

The above code does not work on Linux machines. Here's an update that works on Linux.

from tkinter import Tk # or(from Tkinter import Tk) on Python 2.x
root = Tk()
root.wait_visibility(root)
root.wm_attributes('-alpha',0.3)
root.mainloop()

Not sure if this works on Windows.

like image 164
bhaskarc Avatar answered Oct 21 '22 06:10

bhaskarc