A graphical Tic Tac Toe game built with Python using Tkinter. The board size is customizable (e.g., 3×3, 4×4, etc.), and the game supports two-player mode with X and O.
This project is a Tic Tac Toe game implemented in Python using the Tkinter GUI library. Users can enter the desired board size (e.g., 3 for 3×3, 4 for 4×4) to start the game. Players take turns clicking on empty cells to place their mark (X or O), and the game checks for a winner after each move. If a player wins or the board is full (tie), a message is shown and the board resets automatically.
- Initializes the game window, board matrix, current player, and GUI buttons.
- Creates a grid of buttons in the GUI representing the game board.
- Called when a player clicks on a cell: Places the current player's mark, checks for a win/tie, switches players, or shows an error if the move is invalid.
- Checks all rows, columns, and diagonals to determine if the player has won.
- Determines if the board is completely filled, indicating a tie.
- Resets the board and GUI buttons to start a new game.
- Starts the Tkinter main loop to run the game window.
- Run the program and enter your desired board size (e.g.,
3for a 3×3 game). - Two players take turns: Player X starts, followed by Player O.
- Click an empty cell to place your mark.
- The first player to align all their marks in a row, column, or diagonal wins.
- If all cells are filled and there is no winner, the game ends in a tie.
- The game resets automatically after a win or tie for continuous play.
- Python 3.x
- Tkinter (included by default with most Python installations)
python tic_tac_toe_gui.py