PyGetWindow

0.0.9 · active · verified Fri Apr 10

PyGetWindow is a simple, cross-platform Python module for obtaining graphical user interface (GUI) information on application windows. It allows programmatic interaction with windows, such as listing titles, finding specific windows, and controlling their state (minimize, maximize, activate, resize, move, close). The library is currently at version 0.0.9 and is still under active development, with primary functionality implemented for Windows.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import PyGetWindow, retrieve a list of all visible window titles and window objects, identify the active window, and find a specific window by its title. It also shows commented-out examples of how to interact with a window, such as activating, minimizing, maximizing, or resizing it.

import pygetwindow as gw

# Get a list of all visible window titles
all_titles = gw.getAllTitles()
print(f"All window titles: {all_titles}")

# Get a list of all Window objects
all_windows = gw.getAllWindows()
print(f"Number of open windows: {len(all_windows)}")

if all_windows:
    # Get the currently active (foreground) window
    active_window = gw.getActiveWindow()
    if active_window:
        print(f"\nActive window title: {active_window.title}")
        print(f"Active window position: {active_window.topleft}")
        print(f"Active window size: {active_window.size}")

    # Try to find a specific window (e.g., a browser or editor)
    # Replace 'Chrome' with a title from your `all_titles` list for testing
    try:
        target_window = gw.getWindowsWithTitle('Chrome')[0]
        print(f"\nFound target window: {target_window.title}")
        # Example actions (commented out as they affect your desktop visually)
        # target_window.activate()
        # target_window.minimize()
        # target_window.maximize()
        # target_window.restore()
        # target_window.moveTo(100, 100)
        # target_window.resizeTo(800, 600)
    except IndexError:
        print("\n'Chrome' window not found. Try another title from the list.")

view raw JSON →