PyScreeze

1.0.1 · active · verified Fri Apr 10

PyScreeze is a simple, cross-platform screenshot module for Python 3. It provides functionality to take screenshots, save them to files, and locate images within the screen. This is particularly useful for GUI automation tasks where visual elements need to be identified. The library is currently at version 1.0.1 and typically has an infrequent release cadence, with the last PyPI release in August 2024.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to take full or partial screenshots and how to locate an image on the screen using `screenshot()` and `locateOnScreen()`. The `locateOnScreen()` function returns a 4-integer tuple (left, top, width, height) if found, or raises an `ImageNotFoundException` if not found (default behavior since 1.0.0).

import pyscreeze

# Take a screenshot of the entire screen
im1 = pyscreeze.screenshot()
# Save a screenshot to a file
im2 = pyscreeze.screenshot('my_screenshot.png')

# Take a screenshot of a specific region (left, top, width, height)
# Ensure 'image_path.png' exists for locateOnScreen to work
try:
    region_screenshot = pyscreeze.screenshot(region=(0, 0, 300, 400))
    print(f"Screenshot of region saved as temporary file. Image object: {region_screenshot}")

    # Locate an image on the screen
    # Replace 'path/to/your/button.png' with an actual image file on your screen
    # Ensure an image 'button.png' is in the current directory or provide full path
    button_location = pyscreeze.locateOnScreen('button.png', confidence=0.8)
    if button_location:
        print(f"Button found at: {button_location}")
        center_coords = pyscreeze.center(button_location)
        print(f"Center of button: {center_coords}")
    else:
        print("Button not found on screen.")
except pyscreeze.ImageNotFoundException:
    print("Image not found on screen (expected for 'button.png' if not present).")
except FileNotFoundError:
    print("Ensure 'button.png' exists in the current directory or provide a full path.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →