Build Your First Simple Python Game Tutorial With Code

Logan Jul 13, 2026

Have you ever wanted to create your own game but thought it would be too complex? Think again! Python, with its simple and easy-to-understand syntax, is a fantastic language for creating games. Whether you're a beginner or an experienced programmer, you can make interactive and fun games with Python. In this tutorial, we'll guide you step-by-step to create a simple Python game called "Tic-Tac-Toe".

Game Development with Python Programming...
Game Development with Python Programming...

Before we dive into the code, make sure you have Python installed on your computer. If not, you can download it from the official website: Python Downloads.

How To Make A Pacman Game In Python
How To Make A Pacman Game In Python

The Game Board

Let's start by creating the game board. In Tic-Tac-Toe, the game board is a 3x3 grid. We'll represent this in Python using a list of lists.

Game Development with Python Programming...
Game Development with Python Programming...

Here's how you can initialize the game board:

```python game_board = [[' ' for _ in range(3)] for _ in range(3)] ```

Displaying the Game Board

Pygame Tutorial for Beginners
Pygame Tutorial for Beginners

Now, let's write a function to display the game board. This function will print out the current state of the game board.

Here's the code for displaying the game board:

```python def print_board(board): for row in board: print(' | '.join(row)) print('-' * 9) ```

Making a Move

Text-Based Adventure Game in Python (Complete Guide)
Text-Based Adventure Game in Python (Complete Guide)

In Tic-Tac-Toe, players take turns placing their mark ('X' or 'O') on the board. Let's create a function that allows a player to make a move by entering the row and column number.

Here's the code for making a move:

```python def make_move(board, player, row, col): if board[row][col] != ' ': return False board[row][col] = player return True ```

Game Logic

minecraft game using python programming
minecraft game using python programming

Now, let's write the main game loop. This is where the players will take turns and the game will check for a winner.

Here's the code for the game logic:

Python pygame
Python pygame
Game Development with Python Programming...
Game Development with Python Programming...
Game Development with Python Programming...
Game Development with Python Programming...
Gamedev with Python, Pygame, & MS Paint - Timelapse
Gamedev with Python, Pygame, & MS Paint - Timelapse
Simple Python code for snake game with images
Simple Python code for snake game with images
Build a Tic Tac Toe Game in Python
Build a Tic Tac Toe Game in Python
Game Development with Python Programming...
Game Development with Python Programming...
How to Build A Chess Game in Python?
How to Build A Chess Game in Python?
Creating a Snake Game in Python.
Creating a Snake Game in Python.
Simple, Quick, and Fun Number Guessing Python Game for Beginners
Simple, Quick, and Fun Number Guessing Python Game for Beginners
Python Game Development with Kivy - Flappy Bird Tutorial
Python Game Development with Kivy - Flappy Bird Tutorial
Python Games for Kids to Code
Python Games for Kids to Code
Creating a BlackJack game with Python
Creating a BlackJack game with Python
How to Create A Bouncing Ball in Python?
How to Create A Bouncing Ball in Python?
Game Development with Python
Game Development with Python
42 python project ideas for beginners to use in the next few years, including
42 python project ideas for beginners to use in the next few years, including
Game Development with Python Programming...
Game Development with Python Programming...
Hangman Game in Python - Simple Game Project for Beginners - DataFlair
Hangman Game in Python - Simple Game Project for Beginners - DataFlair
How To Code A Python Text-Based Adventure Game In 11 Minutes | Programming Tutorial For Beginners
How To Code A Python Text-Based Adventure Game In 11 Minutes | Programming Tutorial For Beginners
Emojis in python
Emojis in python

```python def play_game(): board = [[' ' for _ in range(3)] for _ in range(3)] current_player = 'X' while True: print_board(board) row = int(input(f"{current_player}'s turn! Enter row (0-2): ")) col = int(input(f"Enter column (0-2): ")) if make_move(board, current_player, row, col): if check_win(board, current_player): print_board(board) print(f"{current_player} wins!") break elif check_draw(board): print_board(board) print("It's a draw!") break current_player = 'O' if current_player == 'X' else 'X' else: print("Invalid move. Try again.") def check_win(board, player): # Check rows, columns, and diagonals for a win # ... def check_draw(board): # Check if the board is full # ... ```

The `play_game` function initializes the game board, determines the current player, and runs the game loop. It calls `print_board` to display the game board, `make_move` to allow a player to make a move, and checks for a win or a draw using `check_win` and `check_draw`.

The `check_win` and `check_draw` functions are placeholders for the logic that checks for a win or a draw. You'll need to implement these functions yourself.

There you have it! A simple Tic-Tac-Toe game implemented in Python. As you continue to learn and experiment with Python, you can build upon this foundation to create more complex and engaging games. Happy coding!