PyAutoGUI: Cross-Platform GUI Automation with Python

This repository profile is provided by osrepos.com, an open source repository discovery platform.

PyAutoGUI: Cross-Platform GUI Automation with Python

Summary

PyAutoGUI is an intuitive Python module designed for cross-platform GUI automation, enabling users to programmatically control the mouse and keyboard. It simplifies complex desktop interactions, allowing for tasks like clicking, typing, and taking screenshots across Windows, macOS, and Linux. This powerful library is ideal for automating repetitive tasks and creating bots.

Repository Information

Analyzed by OSRepos on August 4, 2026

Use at your own risk

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.

Introduction

PyAutoGUI is a powerful, cross-platform Python module that simplifies GUI automation for human beings. It allows you to programmatically control the mouse and keyboard, making it an excellent tool for automating repetitive tasks, creating bots, or performing desktop interactions without direct human input. Whether you need to click buttons, type text, or capture screenshots, PyAutoGUI provides a straightforward API to achieve these actions across Windows, macOS, and Linux.

Installation

Installing PyAutoGUI is simple using pip. However, note that there are some operating system-specific dependencies.

To install PyAutoGUI:

pip install pyautogui

Dependencies:

  • Windows: No additional dependencies.
  • macOS: Requires pyobjc-core and pyobjc modules.
  • Linux: Needs python3-xlib (or python-xlib for Python 2).
  • All Platforms: Pillow needs to be installed for image-related features. On Linux, additional libraries might be required for Pillow's PNG/JPEG support.

Examples

PyAutoGUI offers a wide range of functions for controlling your GUI. Here are some common use cases:

Keyboard and Mouse Control

Control mouse movement, clicks, and keyboard input. The origin (0,0) is the top-left corner of the screen.

import pyautogui

screenWidth, screenHeight = pyautogui.size() # Returns two integers, the width and height of the screen.
currentMouseX, currentMouseY = pyautogui.position() # Returns two integers, the x and y of the mouse cursor's current position.
pyautogui.moveTo(100, 150) # Move the mouse to the x, y coordinates 100, 150.
pyautogui.click() # Click the mouse at its current location.
pyautogui.click(200, 220) # Click the mouse at the x, y coordinates 200, 220.
pyautogui.move(None, 10)  # Move mouse 10 pixels down, relative to its current position.
pyautogui.doubleClick() # Double click the mouse at the current location.
pyautogui.moveTo(500, 500, duration=2, tween=pyautogui.easeInOutQuad) # Use tweening/easing function to move mouse over 2 seconds.
pyautogui.write('Hello world!', interval=0.25)  # Type with quarter-second pause in between each key.
pyautogui.press('esc') # Simulate pressing the Escape key.
pyautogui.keyDown('shift')
pyautogui.write(['left', 'left', 'left', 'left', 'left', 'left'])
pyautogui.keyUp('shift')
pyautogui.hotkey('ctrl', 'c')

Display Message Boxes

PyAutoGUI can display various types of message boxes, useful for user interaction or debugging.

import pyautogui

pyautogui.alert('This is an alert box.')
pyautogui.confirm('Shall I proceed?')
pyautogui.confirm('Enter option.', buttons=['A', 'B', 'C'])
pyautogui.prompt('What is your name?')
pyautogui.password('Enter password (text will be hidden)')

Screenshot Functions

Capture screenshots and even locate images on the screen.

import pyautogui

im1 = pyautogui.screenshot()
im1.save('my_screenshot.png')
im2 = pyautogui.screenshot('my_screenshot2.png')

# Locate an image on the screen
button7location = pyautogui.locateOnScreen('button.png') # returns (left, top, width, height) of matching region
# Example output: (1416, 562, 50, 41)
buttonx, buttony = pyautogui.center(button7location)
# Example output: (1441, 582)
pyautogui.click(buttonx, buttony)  # clicks the center of where the button was found

# Locate and click the center of an image directly
buttonx, buttony = pyautogui.locateCenterOnScreen('button.png') # returns (x, y) of matching region
# Example output: (1441, 582)
pyautogui.click(buttonx, buttony)  # clicks the center of where the button was found

Why Use PyAutoGUI?

PyAutoGUI excels at abstracting the complexities of operating system-specific GUI automation APIs. Instead of dealing with the intricate details of Windows API, macOS Cocoa API, or Linux X11, developers can use a single, consistent Python interface. This cross-platform compatibility and ease of use make PyAutoGUI an ideal choice for:

  • Automating repetitive tasks: From filling out forms to navigating applications.
  • Testing GUI applications: Creating automated test scripts for user interfaces.
  • Creating simple bots: For games or other desktop applications.
  • Accessibility tools: Assisting users with specific needs by automating interactions.

Its design focuses on being "for human beings," meaning its functions are intuitive and mimic natural user interactions.

Links

Support the Project

If you find PyAutoGUI helpful and wish to support its ongoing development, consider donating to its creator on Patreon: https://www.patreon.com/AlSweigart

Related repositories

Similar repositories that may be relevant next.

nose2: The Successor to nose, Based on unittest2

nose2: The Successor to nose, Based on unittest2

August 4, 2026

nose2 is a powerful testing framework for Python, designed as the successor to the popular nose project. Built upon Python's standard `unittest` module, it extends its capabilities to provide a more flexible and feature-rich testing experience. It aims to make writing and running tests in Python simpler and more efficient.

PythonTestingUnit Testing
Freezegun: Time Travel for Your Python Tests

Freezegun: Time Travel for Your Python Tests

August 4, 2026

Freezegun is a powerful Python library designed to simplify testing by allowing your tests to travel through time. It achieves this by mocking the `datetime` module, enabling developers to freeze time at a specific point or even simulate its progression. This functionality is crucial for ensuring consistent and reliable test results when dealing with time-sensitive logic.

PythonTestingMocking
HTTPretty: Intercepting HTTP Requests for Python Testing

HTTPretty: Intercepting HTTP Requests for Python Testing

August 3, 2026

HTTPretty is a powerful Python library designed to intercept HTTP requests at the socket level, effectively faking the entire socket module. It provides a robust solution for mocking external HTTP services, making it ideal for test-driven development and reliable API integration testing. Developers can use HTTPretty to simulate various HTTP responses, ensuring comprehensive and isolated testing environments.

PythonHTTP MockingTesting
Mixer: A Powerful Fixture Replacement for Python ORMs and ODMs

Mixer: A Powerful Fixture Replacement for Python ORMs and ODMs

August 3, 2026

Mixer is a versatile Python library designed to replace fixtures and generate test data efficiently. It supports various ORMs and ODMs, including Django, SQLAlchemy, Flask-SQLAlchemy, Mongoengine, and Marshmallow, making it an invaluable tool for testing and development workflows.

PythonDjangoFlask

Source repository

Open the original repository on GitHub.

View on GitHub
OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️