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?
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.
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.
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.
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.
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