I am writing a Python application that uses tkinter, and I am trying to give a look more like new W10 applications.
With tkinter, I can apply an image as a frame background or a solid colour using bg, or even make the frame, or the whole window transparent with alpha.
To make the UI look better I have removed the border of the buttons with this parameters borderwidth=0,highlightthickness = 0, bd = 0.
But I haven't find anything to make a blurry transparent frame background. Same as aero or new W10 applications.
With alpha I can change the opacity, but not the blur.
Is there any way to make my application look like I described?
3 Answers
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
kivyskip thiskivyinstallation guide:
REMEMBER : Kivy is supported only in python 2.7, 3.7 and 3.4 so uninstall the python you have if any version does not match. To know current python 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 use
DWM (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
pyautoguipackage - 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 occur
import pyautogui
# take screenshot
screenshot = pyautogui.screenshot()
screenshot.save('screenshot.png')
# import other required libraries
from PIL import Image, ImageFilter
from kivy.app import App
from kivy.core.window import Window
from kivy.uix.widget import Widget
from PIL import Image, ImageFilter
from win32api import GetSystemMetrics
from kivy.animation import Animation
# set window size
Window.borderless = True
Window.size = GetSystemMetrics(0), GetSystemMetrics(1)
Window.left = 0
Window.top = 0
class 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 filesave asbuild.kvelse 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.
You cannot really do it, but you can surely fake it, as demonstrated by @PyGuy. My short code however is plain Tkinter, and pyautogui, that can be helpful, in case you are not familiar with kivy, like me.
import ctypes
import pyautogui
from tkinter import *
from PIL import ImageTk, ImageFilter, ImageEnhance
import tkinter as tk
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root =tk.Tk()
root.geometry("1500x1200")
frame=Frame(root)
x = 3
y = 37
ss = pyautogui.screenshot(region=(x, y, 1950, 1200))
blurImage = ss.filter(ImageFilter.GaussianBlur(radius = 20))
filter=ImageEnhance.Brightness(blurImage)
brightImage=filter.enhance(0.8)
brightImage = brightImage.filter(ImageFilter.SMOOTH_MORE())
ss = ImageTk.PhotoImage(brightImage)
root.state('zoomed')
image1 = Label(frame, image=ss)
image1.image = ss
image1.place(x=0, y=0)
frame.config(bg="white")
frame.pack(expand="true", fill=BOTH)
root.state('zoomed')
root.mainloop()