嗯,这在tkinter 中是完全不可能的,但等等,我并不是说不可能。
您只需要执行以下操作-
注意:仅当您在没有边框的全屏窗口中使用您的应用时,这才有效。
让我们看看如何-我将使用KIVY所以请下载它。
如果您有kivy,请跳过此kivy 安装指南:
记住:Kivy 仅在 python 2.7、3.7 和 3.4 中受支持,所以
卸载
如果任何版本不匹配,您将拥有 python。要知道当前
python version 在cmd中输入'python version'。
步骤 1)。在 cmd 中输入“pip install kivy”
步骤 2)。安装过程中可能会出现问题,所以我说卸载不支持的python版本。
1)。以下软件包是必需的,如果您没有,请下载它们。
- PIL
pip install PIL
- pyautogui
pip install pyautogui
2)。说明:在Python中,有点难用
DWM(桌面窗口管理器)API,有助于模糊后面的窗口。然而,
在 C++ 中,有一个名为 EnableBlurBehind() 的内置函数可以使用 DWM API 模糊后面的窗口。
- 首先,我们将使用
pyautogui 包进行截图
- 然后模糊图像(屏幕截图或背景)
- 最后,在画布中设置图片。
瞧!你把后面的窗户弄模糊了。因此,让我们让这个概念发挥作用。
仅当您下载了所需的库后,才复制并粘贴到 IDE 中
# 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 file 另存为build.kv 否则无效
<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()
如果您不知道如何在 IDE 中打开 file.kv,请搜索它。解决您遇到的任何非常规问题。