【问题标题】:How to capture image behind window in python (tkinter)如何在python(tkinter)中捕获窗口后面的图像
【发布时间】:2020-03-06 17:28:54
【问题描述】:

我喜欢捕捉窗口后面的像素,用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()

如果您需要更多信息,请直接说出来。

(对不起我的英语不好)

【问题讨论】:

  • “是否可以做”:是的,如果你在.withdraw()你的MainWindow之前grab像素或之前显示MainWindow
  • @stovfl 这会使窗口闪烁,我想要它完全平滑

标签: python tkinter python-imaging-library blur


【解决方案1】:

在 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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-28
    • 2014-07-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-30
    相关资源
    最近更新 更多