This project provides a Docker-based solution for automating interactions with pygame GUI applications and capturing screenshots. It's specifically designed to work with the Tic-Tac-Toe game but can be adapted for other pygame applications.
- 🖥️ Virtual Display: Runs pygame applications in a headless Docker environment using Xvfb
- 🎮 Input Automation: Supports keyboard events and mouse clicks
- 📸 Screenshot Capture: Automatically takes screenshots after each action
- 🐳 Containerized: Fully contained Docker environment with all dependencies
- 🔧 Easy to Use: Simple command-line interface for automation
docker build -t pygame-automation .Run with automation commands:
# Create a screenshots directory
mkdir screenshots
# Run automation with commands
docker run --rm -v $(pwd)/screenshots:/app/screenshots pygame-automation \
"click 100 100" \
"click 300 300" \
"keyboard r" \
"screenshot"# Make the example script executable and run it
chmod +x example_usage.py
python example_usage.py| Command | Description | Example |
|---|---|---|
click <x> <y> |
Click at coordinates (x, y) | click 200 300 |
keyboard <key> |
Send keyboard event | keyboard w |
screenshot |
Take a manual screenshot | screenshot |
wait |
Wait for 1 second | wait |
- Game controls:
w,a,s,d - Game actions:
r(restart) - Special keys:
space,enter,esc - Any other single character key
For the Tic-Tac-Toe game (600x600 pixels), the grid squares are approximately:
(100,100) (300,100) (500,100)
(100,300) (300,300) (500,300)
(100,500) (300,500) (500,500)
godot-image/
├── Dockerfile # Docker image definition
├── requirements.txt # Python dependencies
├── game.py # Your pygame application
├── automation.py # Automation and screenshot logic
├── start.sh # Container startup script
├── example_usage.py # Example automation scripts
└── README.md # This file
docker run --rm -v $(pwd)/screenshots:/app/screenshots pygame-automation \
"click 100 100" \
"click 300 300" \
"click 500 500"docker run --rm -v $(pwd)/screenshots:/app/screenshots pygame-automation \
"click 300 300" \
"click 100 100" \
"click 500 500" \
"click 100 500" \
"click 300 100" \
"keyboard r" \
"screenshot"# Run without commands to see available options
docker run --rm -v $(pwd)/screenshots:/app/screenshots pygame-automationScreenshots are automatically saved after each action with descriptive names:
screenshot_001_initial.png- Initial game statescreenshot_002_click_100_100.png- After clicking at (100,100)screenshot_003_keyboard_r.png- After pressing 'r' keyscreenshot_004_manual.png- Manual screenshot
To use with a different pygame application:
- Replace
game.pywith your pygame application - Update the window detection in
automation.py(search for window name) - Adjust coordinates and commands as needed
Edit automation.py and add new command handlers in the execute_command method:
elif command.startswith("my_command "):
# Your custom command logic here
passTo see what's happening inside the container:
# Run interactively
docker run -it --rm -v $(pwd)/screenshots:/app/screenshots pygame-automation bash
# Inside container, start display and run components manually
Xvfb :99 -screen 0 1024x768x24 &
export DISPLAY=:99
python game.py &
python automation.py "screenshot"- No screenshots generated: Check that the screenshots directory is mounted correctly
- Commands not working: Ensure the virtual display is ready (the system waits automatically)
- Game not responding: Check that the game window is properly detected
Container logs will show:
- Virtual display startup
- Game initialization
- Command execution status
- Screenshot save confirmations
- Docker
- At least 1GB RAM for the container
- Write permissions for screenshot directory
This project is provided as-is for educational and development purposes.