Play Tic Tac Toe against a computer opponent with a visual interface built in Tkinter.
This project provides a GUI-based Tic Tac Toe game using Python's Tkinter. You can play against a basic AI opponent that tries to win or block your moves. The game keeps track of the scoreboard including wins, losses and draws and highlights winning cells.
- Interactive 3x3 grid interface using Tkinter
- Play against a computer opponent
- Tracks and updates scoreboard for Player, Opponent and Draws
- Highlights winning cells
- Restart button to reset the game at any time
- Easy-to-read and modular code with separate classes for gameplay, grid UI and opponent logic
- Clone the repository
git clone https://github.com/yourusername/tic-tac-toe-gui.git
cd tic-tac-toe-gui
- Install dependencies
pip install -r requirements.txt
- Run the game
python main.py
The game window will open, allowing you to play against the computer. Scores will update automatically and winning cells are highlighted.
- Python 3.10+
- Tkinter (usually included with Python)
Optional: No external packages are required as Tkinter is standard with Python.
- The AI opponent uses a simple strategy: tries to win first, blocks the player, then picks the first available cell.
- Highlighted cells turn green when a player or the opponent wins.
- Restart button clears the board but keeps the scores.
- All game logic is separated into
gameplay.py,grid.pyandopponent.pyfor easy maintenance and extension.
This project is licensed under the MIT License.