top of page

Create a Sudoku puzzle: Python Project

In this tutorial, we are going to create a Sudoku puzzle using pygame and beautiful soup.

What is a Sudoku puzzle?

The goal of this puzzle is to fill a 9x9 grid with numbers from 1 to 9, so that each row, column, and 3x3 sub-grid have no other duplicate.

Why pygame?

Python alone is not enough to build a game. Pygame is an external library of python that can help python to write a game. It contains generates an interface where we can interact with python.

Getting started

Install virtual environment

pip install virtualenv

Create a Virtual environment in the folder your project is in and activate

virtualenv env

to active in windows


to activate in UNIX and MAC

source env/bin/activate

After setting up your environment, install:

pip install pygame beautifulsoup

Create two python files,, and in the project folder. file is the core file to run the project. file is to set the interface height and width.

File structure





| this is the python file you need to run for the game run. in this file, we will decide the settings for the game. Like the height and width of the game window, font size, font-weight, etc. in this file, we write the functions when the buttons in the game are pressed. this is the core file where all mathematical and logical operations are written.


Below is the screenshot for the sudoku game after running The window comprises five buttons, namely submit, easy, medium, Hard, Evil.

Easy, medium, hard and evil are the difficulty level settings of the puzzle.

Give your input in blank blocks and submit your answer. After submitting, blank blocks and wrong answer block turns red, otherwise stays as a white block.

bottom of page