I am creating a python script which has blurred background. Here's the code:
from tkinter import Tk, PhotoImage, Label, Button
from tkinter.constants import BOTH
from PIL import ImageFilter
import pyautogui as pg
import os
import threading as th
root = Tk()
root.title("Blur window")
root.resizable(0, 0)
def place_center():
global x, y
reso = pg.size()
rx = reso[0]
ry = reso[1]
x = int((rx/2) - (500/2))
y = int((ry/2) - (500/2))
root.geometry(f"500x500+{x}+{y}")
def blur():
while True:
img = pg.screenshot(region=(root.winfo_x(), root.winfo_y(), 500, 500))
try:
img = img.filter(ImageFilter.GaussianBlur(10))
img.save("C:\\Users\\username\\AppData\\Local\\Temp\\blurred_bg.png")
bgimg = PhotoImage(file="C:\\Users\\username\\AppData\\Local\\Temp\\blurred_bg.png")
bg.config(image=bgimg)
except Exception:
pass
place_center()
bg = Label(root, image='')
bg.pack(fill=BOTH, expand=1)
th.Thread(target=blur).start()
root.mainloop()
When I run the program, the window takes screenshot of itself, which I don't want. I want it to take screenshot of the content exactly behind the window.
I tried using root.attributes("-alpha")
before and after using the screenshot, but that looks odd.
Here's a short video of the running program
Any suggestions/help will be appreciated. Thank you!