Can python get the screen shot of a specific window?

There are multiple ways to do that. The code for these will require modification based on your needs, so I will put in some pointers to the high level methods and libraries:

  1. You can directly use GUI-automation tools such as Pyautogui to press Alt+PrntScreen and transfer the data from clipboard into a variable (http://pyautogui.readthedocs.io/en/latest/keyboard.html#keyboard-keys)

  2. You can use pywin32 and PIL to grab the image of a certain window (How to Get a Window or Fullscreen Screenshot in Python 3k? (without PIL))

  3. You can use imagemagik to grab screenshots of a single window (https://www.imagemagick.org/discourse-server/viewtopic.php?t=24702)

  4. You can use Pyautogui.locateOnScreen(“Sceenshot.PNG”) to find the tuple which will contain the boundaries of the window for your java app. Then you can pass it to your functionimg.ImageGrab.grab(bbox)`

Leave a Comment