{"id":2690,"library":"pygetwindow","title":"PyGetWindow","description":"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.","status":"active","version":"0.0.9","language":"en","source_language":"en","source_url":"https://github.com/asweigart/pygetwindow","tags":["gui","window management","automation","cross-platform","desktop"],"install":[{"cmd":"pip install pygetwindow","lang":"bash","label":"Install PyGetWindow"}],"dependencies":[],"imports":[{"note":"The 'gw' alias is a common convention for PyGetWindow.","symbol":"pygetwindow","correct":"import pygetwindow as gw"},{"note":"The PyGetWindowException must be explicitly imported to be caught directly, not accessed as an attribute of the top-level module.","wrong":"except pygetwindow.PyGetWindowException","symbol":"PyGetWindowException","correct":"from pygetwindow import PyGetWindowException"}],"quickstart":{"code":"import pygetwindow as gw\n\n# Get a list of all visible window titles\nall_titles = gw.getAllTitles()\nprint(f\"All window titles: {all_titles}\")\n\n# Get a list of all Window objects\nall_windows = gw.getAllWindows()\nprint(f\"Number of open windows: {len(all_windows)}\")\n\nif all_windows:\n    # Get the currently active (foreground) window\n    active_window = gw.getActiveWindow()\n    if active_window:\n        print(f\"\\nActive window title: {active_window.title}\")\n        print(f\"Active window position: {active_window.topleft}\")\n        print(f\"Active window size: {active_window.size}\")\n\n    # Try to find a specific window (e.g., a browser or editor)\n    # Replace 'Chrome' with a title from your `all_titles` list for testing\n    try:\n        target_window = gw.getWindowsWithTitle('Chrome')[0]\n        print(f\"\\nFound target window: {target_window.title}\")\n        # Example actions (commented out as they affect your desktop visually)\n        # target_window.activate()\n        # target_window.minimize()\n        # target_window.maximize()\n        # target_window.restore()\n        # target_window.moveTo(100, 100)\n        # target_window.resizeTo(800, 600)\n    except IndexError:\n        print(\"\\n'Chrome' window not found. Try another title from the list.\")\n\n","lang":"python","description":"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."},"warnings":[{"fix":"Thoroughly test on your target operating system. For critical cross-platform applications, consider platform-specific fallbacks or alternative libraries with robust support for your target OS.","message":"PyGetWindow's cross-platform support is currently limited. While designed to be cross-platform, full functionality is primarily implemented and tested on Windows. Support for macOS is partial, and Linux has known issues or lacks certain features. Some methods might raise exceptions or not work as expected on non-Windows systems.","severity":"gotcha","affected_versions":"0.0.1 - 0.0.9"},{"fix":"Always use `from pygetwindow import PyGetWindowException` when you intend to catch this specific exception.","message":"To catch `PyGetWindowException` (e.g., when a window is not found), you must import it directly using `from pygetwindow import PyGetWindowException`. Attempting to catch `pygetwindow.PyGetWindowException` will result in a `NameError` if `pygetwindow` was imported with an alias like `import pygetwindow as gw` and `PyGetWindowException` was not explicitly imported.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the GitHub issues for known bugs and potential workarounds. Be prepared for occasional unexpected behavior or missing functionality, especially for edge cases.","message":"The library is still under development, and some features may be incomplete or unstable. There are reported issues such as incorrect window location coordinates (sometimes exacerbated when used with PyAutoGUI), inability to retrieve minimized windows, and problems with the `__str__` representation of `Window` objects.","severity":"gotcha","affected_versions":"All versions (0.0.1 - 0.0.9)"},{"fix":"Use these functions cautiously in production environments. Ensure users are aware of potential GUI interactions. Consider running automation in isolated virtual environments or during off-hours if visual interference is a concern.","message":"Window manipulation methods like `activate()`, `minimize()`, `maximize()`, `moveTo()`, and `resizeTo()` directly interact with the operating system's GUI. They can cause visual changes on the user's screen and might interfere with user input, especially in automated scripts running in the foreground.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}