我想知道如何在 tkinter 中创建模糊透明效果。我已经知道如何使用
为窗口添加透明效果root=Tk()
root.attributes("-alpha",0.95)
但是如何添加模糊部分呢?
该服务不是由 tkinter 提供的。但是,您可以拍摄应用程序的屏幕截图并自行对其进行模糊处理(例如参见ImageFilter.GaussianBlur或numpy.gaussian过滤器)。
您应该使用 “BlurWindow” 软件包并按以下方式安装:
python -m pip install BlurWindow
from tkinter import *
from ctypes import windll
from BlurWindow.blurWindow import blur
root = Tk()
root.config(bg='green')
root.wm_attributes("-transparent", 'green')
root.geometry('500x400')
root.update()
hWnd = windll.user32.GetForegroundWindow()
blur(hWnd)
def color(hex):
hWnd = windll.user32.GetForegroundWindow()
blur(hWnd,hexColor=hex)
e = Entry(width=9)
e.insert(0,'#12121240')
e.pack()
b = Button(text='Apply',command=lambda:[color(e.get())])
b.pack()
root.mainloop()
您还可以使用pywinstyles 应用像丙烯酸/航空一样的模糊效果。
import tkinter
import pywinstyles
root = tkinter.Tk()
pywinstyles.apply_style(root, "acrylic")
root.mainloop()