Cross-platform GUI automation library that enables programmatic control of mouse, keyboard, and screen interactions.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Cross-platform dialog boxes for user interaction including alerts, confirmations, text input, and password prompts. These functions provide a simple way to display information and collect user input through native system dialogs.
Display informational messages to the user with a single acknowledgment button.
def alert(text='', title='', button='OK'):
"""
Display an alert message box with single button.
Parameters:
- text (str): Message text to display (default: '')
- title (str): Window title (default: '')
- button (str): Button text (default: 'OK')
Returns:
str: Text of the button clicked (always the button parameter value)
Example:
pyautogui.alert('Process completed successfully!', 'Success')
pyautogui.alert('Warning: This action cannot be undone', 'Warning', 'I Understand')
"""Present the user with multiple choice options for decision making.
def confirm(text='', title='', buttons=['Cancel', 'OK']):
"""
Display confirmation dialog with multiple buttons.
Parameters:
- text (str): Message text to display (default: '')
- title (str): Window title (default: '')
- buttons (list): List of button text options (default: ['Cancel', 'OK'])
Returns:
str: Text of the button clicked, or None if dialog was closed/cancelled
Examples:
result = pyautogui.confirm('Save changes before closing?', 'Confirm', ['Save', 'Don\'t Save', 'Cancel'])
if result == 'Save':
# Save the file
pass
elif result == 'Don\'t Save':
# Close without saving
pass
# If result is 'Cancel' or None, do nothing
"""Collect text input from the user through input dialog boxes.
def prompt(text='', title='', default=''):
"""
Display text input dialog box.
Parameters:
- text (str): Prompt message to display (default: '')
- title (str): Window title (default: '')
- default (str): Default text in input field (default: '')
Returns:
str: User input text, or None if dialog was cancelled
Examples:
name = pyautogui.prompt('Enter your name:', 'User Registration')
if name:
print(f"Hello, {name}!")
filename = pyautogui.prompt('Save as:', 'Save File', default='document.txt')
"""Collect sensitive text input with masked display for password and credential entry.
def password(text='', title='', default='', mask='*'):
"""
Display password input dialog with masked text entry.
Parameters:
- text (str): Prompt message to display (default: '')
- title (str): Window title (default: '')
- default (str): Default text in input field (default: '')
- mask (str): Character to display instead of actual characters (default: '*')
Returns:
str: User input text (unmasked), or None if dialog was cancelled
Examples:
password = pyautogui.password('Enter password:', 'Login')
if password:
# Use password for authentication
authenticate(password)
pin = pyautogui.password('Enter PIN:', 'Security', mask='•')
"""import pyautogui
# Simple alert notifications
pyautogui.alert('File saved successfully!')
pyautogui.alert('Operation completed', 'Status Update')
pyautogui.alert('Custom button text', title='Custom Title', button='Got It')
# Confirmation dialogs
result = pyautogui.confirm('Do you want to continue?')
if result == 'OK':
print("User chose to continue")
else:
print("User cancelled or closed dialog")
# Custom confirmation with multiple options
choice = pyautogui.confirm(
'What would you like to do with this file?',
'File Action',
['Open', 'Delete', 'Rename', 'Cancel']
)
if choice == 'Open':
# Open the file
pass
elif choice == 'Delete':
# Delete the file
pass
elif choice == 'Rename':
# Rename the file
pass
# If choice is 'Cancel' or None, do nothing
# Text input prompts
username = pyautogui.prompt('Enter username:', 'Login')
if username:
password = pyautogui.password('Enter password:', 'Login')
if password:
print(f"Attempting login for user: {username}")
# Perform login with username and password
else:
print("Password entry cancelled")
else:
print("Username entry cancelled")
# Input with default values
email = pyautogui.prompt(
'Enter your email address:',
'Account Setup',
default='user@example.com'
)
# Complex workflow with error handling
def get_user_credentials():
"""Get username and password from user with validation"""
while True:
username = pyautogui.prompt('Username:', 'Login Required')
if username is None: # User cancelled
return None, None
if not username.strip():
pyautogui.alert('Username cannot be empty!', 'Error')
continue
password = pyautogui.password('Password:', 'Login Required')
if password is None: # User cancelled
return None, None
if len(password) < 6:
pyautogui.alert('Password must be at least 6 characters!', 'Error')
continue
return username, password
# Use the function
username, password = get_user_credentials()
if username and password:
print("Credentials obtained successfully")
else:
print("Login cancelled by user")
# Save/Don't Save/Cancel pattern
def prompt_save_changes():
"""Common save dialog pattern"""
response = pyautogui.confirm(
'You have unsaved changes. What would you like to do?',
'Unsaved Changes',
['Save', "Don't Save", 'Cancel']
)
if response == 'Save':
# Save the document
filename = pyautogui.prompt('Save as:', 'Save Document', default='untitled.txt')
if filename:
print(f"Saving as {filename}")
return 'saved'
else:
return 'cancelled' # User cancelled save dialog
elif response == "Don't Save":
return 'discard'
else: # Cancel or None
return 'cancelled'
# Configuration and setup dialogs
def setup_application():
"""Application setup using multiple dialogs"""
# Get user preferences
name = pyautogui.prompt('Enter your name:', 'Setup')
if not name:
return False
# Theme selection
theme = pyautogui.confirm(
'Choose your preferred theme:',
'Theme Selection',
['Light', 'Dark', 'Auto']
)
if not theme:
return False
# Auto-save preference
autosave = pyautogui.confirm(
'Enable auto-save every 5 minutes?',
'Auto-save',
['Yes', 'No']
)
# Summary
summary = f"""Setup Summary:
Name: {name}
Theme: {theme}
Auto-save: {autosave}"""
confirm_setup = pyautogui.confirm(
summary + '\n\nProceed with these settings?',
'Confirm Setup',
['Yes', 'No']
)
return confirm_setup == 'Yes'
# Run setup
if setup_application():
pyautogui.alert('Setup completed successfully!', 'Welcome')
else:
pyautogui.alert('Setup cancelled', 'Setup')# Always check for None return values
result = pyautogui.confirm('Continue?')
if result is None:
print("Dialog was closed or cancelled")
elif result == 'OK':
print("User confirmed")
else:
print(f"User selected: {result}")
# Safe text input handling
text = pyautogui.prompt('Enter text:')
if text is not None: # User didn't cancel
if text.strip(): # User entered non-empty text
process_text(text)
else:
print("Empty text entered")
else:
print("Input cancelled")PyAutoGUI's message box functions are provided by the PyMsgBox library. For advanced usage or additional dialog types, you can import PyMsgBox directly:
import pymsgbox
# PyAutoGUI functions are aliases for PyMsgBox functions
# These are equivalent:
pyautogui.alert('Message')
pymsgbox.alert('Message')Install with Tessl CLI
npx tessl i tessl/pypi-pyautogui