Tic Tac Toe Game using PyQt5 in Python
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 :