In this article , we will see how we can create a Tic Tac Toe game using PyQt5. Tic-tac-toe, noughts, and crosses, or Xs and Os is a paper-and-pencil game for two players, X and O, who take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner.
Below is how the Tic Tac Toe game will look like :
GUI implementation steps :
1. Create a list of push buttons
2. Arrange them in 3×3 order and add font to them
3. Create a label below the push buttons that tells the result
4. Set alignment and font to the label
5. Add another push button for reset the game at the bottom
Back end implementation steps :
1. Create two variable to know whose chance is and to know how many chances are completed
2. Add same action to the list of buttons such that each buttons should call the same action
3. Inside the action method get the button by whom method is called using sender method
4. Set the text to the button according to the chance and make it disabled so that it can’t be pressed again and call the who_wins method
5. Set text according to the answer returned by the who_wins method
6. Inside the who_wins method check if rows, columns and diagonals are crossed or not.
7. If someone won the match set the text to the label and make all the buttons disabled
8. Add action to the reset button
9. Inside the reset button action make the variable value set to the starting value and make all the push button enabled and make the label and button text to blank.
Below is the implementation :
- Python implementation of automatic Tic Tac Toe game using random number
- Tic Tac Toe GUI In Python using PyGame
- Draw a Tic Tac Toe Board using Python-Turtle
- PyQt5 - Snake Game
- PyQt5 - The Color Game
- PyQt5 - Number Guessing Game
- PyQt5 – Jumble Word Game
- PyQt5 - Rock Paper and Scissor Game
- Color game using Tkinter in Python
- Python | Simple FLAMES game using Tkinter
- Mastermind Game using Python
- Number Guessing Game in Python using Binary Search
- Create a Simple Two Player Game using Turtle in Python
- Create pong game using Python - Turtle
- 8-bit game using pygame
- How to create Buttons in a game using PyGame?
- Building and visualizing Sudoku Game Using Pygame
- Flipping Tiles (memory game) using Python3
- Hangman Game in Python
- Conway's Game Of Life (Python Implementation)
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.