Tkinter: Blurry transparent background frames
Unfortunately, this service was a matter of argument in tkinter and it's not provided by it. However, you can visit here to know how to use gaussian blur method in your app.
Well, that's quite not possible in tkinter
but wait I am not saying impossible.
You just need to do the following-
NOTE: This works only if you use your app in a full-screen window without borders.
Let us see how- I'm gonna use KIVY
so please download it.
If you have
kivy
skip thiskivy
installation guide:
REMEMBER : Kivy is supported only in python 2.7, 3.7 and 3.4 souninstall thepython you have if any version does not match. To know currentpython version type 'python version' in cmd.
step 1). Type 'pip install kivy' in cmd
step 2). There might be an issue during the installation so as I said unistall unsupported python version.
1). Following packages are required so please download them if you don't have any of them.
- PIL
pip install PIL
- pyautogui
pip install pyautogui
2). Explanation: In Python, it is a bit difficult to useDWM
(Desktop Window Manager) API that helps to blur the window behind. However,in C++ there is a built-in function called EnableBlurBehind()
to blur the window behind using DWM API.
- First, we are going to take a screenshot using
pyautogui
package - Then blur the image (screenshot or background)
- Finally, set the image in canvas.
Voila! You have blurred the window behind. So let us get the concept working.
Copy this and paste into IDE only if you have downloaded the required library
- Main python file, save as name.py
# first take the screenshot else problem will occurimport pyautogui# take screenshotscreenshot = pyautogui.screenshot()screenshot.save('screenshot.png')# import other required librariesfrom PIL import Image, ImageFilterfrom kivy.app import Appfrom kivy.core.window import Windowfrom kivy.uix.widget import Widgetfrom PIL import Image, ImageFilterfrom win32api import GetSystemMetricsfrom kivy.animation import Animation# set window sizeWindow.borderless = TrueWindow.size = GetSystemMetrics(0), GetSystemMetrics(1)Window.left = 0Window.top = 0class Blur(Widget): # Transparent Blur Window Exmple the screenshot get_image = Image.open('screenshot.png') blur_image = get_image.filter(ImageFilter.GaussianBlur(radius=15)) blur_image.save('blured.png') def anim(self): animator = Animation(x=1800, y=500) animator.start(self.ids.animate)class Build(App): def build(self): return Blur()Build().run()
KV Language file
save asbuild.kv
else it won't work
<Blur>: canvas.before: Rectangle: pos: self.pos size: self.size source: 'blured.png' Button: id: animate text: 'Here, you can add anything you want now. Click me!' bold: True italic: True pos: 700, 500 font_size: 25 size: 400, 300 background_color: 0,0,0,0 on_press: root.anim()
If you don't know how to open file.kv
in your IDE search it. Fix any unconventional issues that you have.