Capturing screenshot of running programs in Linux using python

Viewed 1138

Is there any possible way of capturing the screenshot of running desktop application in python using its PID. The application is started from within the python program .

I am familiar with win32gui in windows but I don't know it's alternative in Linux. Win32gui can find windows of running program by its name. Is there any way to do the same in Linux, if PID solution is not possible.

1 Answers

Finally, I got it. Actually, there is a library to do called Xlib (X11 APIs for python), but its documentation is very poor. Hence wasting time on it is not worth it. If you are using Linux, then use simple bash commands to take screenshots of your running desktop application. Code is as follows,

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

For this install wmctrl. In case, if you don't know the Application name use,

wmctrl -l

It will list all the opened desktop applications.

Related