2

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.

Suraj Singh
  • 316
  • 4
  • 10
  • You are expected to perform basic research and make an effort. [Take a screenshot via a Python script on Linux](https://stackoverflow.com/q/69645/608639), [Taking screenshot from a python script by selecting the area](https://stackoverflow.com/q/4921954/608639), [Capturing screenshots with Python in Windows and Linux](https://stackoverflow.com/q/9804878/608639), [Getting a window's PID by clicking on it](https://unix.stackexchange.com/q/19161), [Tell a process PID by it's window?](https://askubuntu.com/q/137875), etc. – jww Jun 20 '19 at 20:33
  • 1
    Hi jww, Thanks for the reply. But if you have read my question carefully then you must know that I already have the PID of the application which I am starting from my python script. What I need to do is to grab a screenshot of that runing application. That link you mentioned i have already gone through them, they all are grabbing the whole screen. Do you know any method from which I can grab the screenshot of desired application or I can get it displays coordinates on screen So that I can capture that particular area? I have already done a lot amount of google search. – Suraj Singh Jun 21 '19 at 18:49

1 Answers1

2

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.

Suraj Singh
  • 316
  • 4
  • 10