使用 python 捕获 Linux 中 运行 个程序的屏幕截图

Capturing screenshot of running programs in Linux using python

是否有任何可能的方法使用其 PID 捕获 python 中 运行 桌面应用程序的屏幕截图。 该应用程序从 python 程序中启动。

我熟悉 windows 中的 win32gui,但我不知道它在 Linux 中的替代方法。 Win32gui 可以通过名称找到 windows of 运行 程序。如果无法使用 PID 解决方案,在 Linux 中是否有任何方法可以做到这一点。

终于,我明白了。实际上,有一个名为 Xlib(X11 APIs for python)的库可以做,但它的文档很差。因此,在上面浪费时间是不值得的。如果您使用 Linux,则使用简单的 bash 命令截取 运行 桌面应用程序的屏幕截图。代码如下,

import os 
os.system("wmctrl -a Application_Name")
os.system("gnome-screenshot -w -f filename.png")

为此安装 wmctrl。如果您不知道应用程序名称,请使用

wmctrl -l

它将列出所有打开的桌面应用程序。