For example, I am running a java program. Can I use python to get the content(screenshot) of this java program? Not the full screen, just the java program.
I have seen this module, but it required a parameter of "where the program window is":
import pyscreenshot as ImageGrab
if __name__ == "__main__":
# part of the screen
im=ImageGrab.grab(bbox=(10,10,510,510)) # X1,Y1,X2,Y2
im.show()
#-#
But this may not be what I am seeking since it requires the bounding_box.
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:
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)
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))
You can use imagemagik to grab screenshots of a single window (https://www.imagemagick.org/discourse-server/viewtopic.php?t=24702)
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 function
img.ImageGrab.grab(bbox)`
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With