【发布时间】: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