python - 如何在python(tkinter)中捕获窗口后面的图像
问题描述
我喜欢捕捉窗口后面的像素,用Pillow
包装模糊它们,最后将它们显示为框架上的图像。
除了一个未解决的问题,我什么也找不到:Python Tkinter get image of whats behind a window
是否可以在 Python 3.7 中做到这一点?
以下是代码的示例:
import tkinter as tk
from PIL import Image, ImageTk
class MainWindow(tk.Tk):
def __init__(self):
super(MainWindow, self).__init__()
self.overrideredirect(True)
self.frame = tk.Frame(self, relief="flat", bd=0)
self.label = tk.Label()
def mainloop(self, n=0):
while self.winfo_exists():
background = Image.frombytes("RGB", ..., ...)
tk_backkground = ImageTk.PhotoImage(background)
self.label.config(image=tk_backkground)
self.update()
self.update_idletasks()
if __name__ == '__main__':
root = MainWindow()
root.mainloop()
如果您需要更多信息,请直接说出来。
(对不起,我的英语不好)
解决方案
在 Windows 中,您可以使用 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()
推荐阅读
- php - Check for similar text in arrays php
- java - for循环中的静态值
- javascript - 如何将多个复选框值显示到文本框从一个文件到另一个
- angular - Angular - 路由重写网址
- android - 应用程序运行 android 时未收到 Cloud Firestore 通知
- javascript - 当我们在javascript ES6(ES2015)中声明变量时,使用(let)和(const)之间的核心区别是什么?
- java - 有没有办法使用 Substance 从 JMenuBar 中删除这个搜索图标和栏?
- javascript - iOS中的expo后台推送通知
- c# - 从总价中正确扣除折扣?
- javascript - 通过鼠标单击加载图像