How to capture the screen output of a running program?

Is it possible to take screenshots of a running program (with GUI) from another python program ? If so, what could be the steps and libraries that I could use ? (On Windows)

For example, let's say I have calc.exe running. I'd want to take screenshots of what is displayed to the user from myprogram.py.

My goal is to analyze what's displayed on the monitored program.

If it's not possible to isolate the screenshot to a running predefined program, I think I will have to take screenshots of the fullscreen but it's not very practical.


Capturing an screenshot is easy. Just install the Python Imaging Library and use the ImageGrab.grab() function to return an Image instance with the screenshot.

Capturing an specified window is a little more complicated, because you need the window coordinates. I recommend you to install the win32api modules and use a little module called winGuiAuto.py. Once you do that, you can do something like this:

hwnd = winGuiAuto.findTopWindow(title) rect = win32gui.GetWindowPlacement(hwnd)[-1] image = ImageGrab.grab(rect)

However, capturing the screen is the easy part. If you want to analyze the contents from screenshots, you're in for a lot of complications. This is probably the wrong approach for doing what you want and should be left as a last resort.

In most cases, it's easier to use the windows api to read the contents of a window's elements directly, but that won't work with some 3rd party GUI toolkits. That's not within the scope of your question so I'm not detailing it here, but you should read the source of the winGuiAuto.py module mentioned above for examples on how to do that, as well as checking the pywinauto library.


The ImageGrab Module, works on Windows only. The pyscreenshot module, is a better replacement for that, can be used to copy the contents of the screen to a PIL or Pillow image memory. Read more at link below.



  • Python save xlPicture from clipboard
  • Several issues with capturing a screen video with python
  • What is the difference between GetComponent ().enabled and .SetActive (false); in unity
  • Youtube Video Player Fullscreen click event
  • Flash radiobutton: how do I get the selected radiobutton?
  • Getting error 'Cannot read property 'document' of undefined' while importing exp
  • How to access culture data in globalize.js V1.0.0
  • During installation of Django, why do I keep getting ImportError: No module named django?
  • where do I find the xml.dom python package for the python-2.6.0-8.9.28 and I have a suse/x86_64 vers
  • Python pickle not one-to-one: different pickles give same object
  • How to generate and display a QR Code in ionic 2
  • What's the purpose of QString?
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Parsing a CSV string while ignoring commas inside the individual columns
  • How do I get HTML corresponding to current DOM tree?
  • Xcode 4 NSLog Macro link in Xcode 3
  • Hardware Accelerated Image Scaling in windows using C++
  • debug library loaded with ctypes using gdb
  • Make VS2015 use angular-cli ng at build time in a .NET project
  • Combining SpatialPolygonsDataFrame of two neighbour countries
  • Python urlparse: small issue
  • How to create a file in java without a extension
  • Exception “firebase.functions() takes … no argument …” when specifying a region for a Cloud Function
  • Highlight one bar in a series in highcharts?
  • FileReader+canvas image loading problem
  • Is there any way to access browser form field suggestions from JavaScript?
  • Does CUDA 5 support STL or THRUST inside the device code?
  • Why winpcap requires both .lib and .dll to run?
  • Calling of Constructors in a Java
  • PHP: When would you need the self:: keyword?
  • python draw pie shapes with colour filled
  • Django query for large number of relationships
  • reshape alternating columns in less time and using less memory
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • How can I use `wmic` in a Windows PE script?
  • Net Present Value in Excel for Grouped Recurring CF
  • How to push additional view controllers onto NavigationController but keep the TabBar?
  • jQuery Masonry / Isotope and fluid images: Momentary overlap on window resize
  • How to load view controller without button in storyboard?