Author image

Snake Applesken - Python PyGame & cx_Freeze Tutorial


KeyC0de's take on the classic Snake game he played back in the day on Nokia 3310 and Sony Ericsson W810i.

If you'd like some implementation help on how I went about to do this I hereby give you my notes below:

snake game pygame overview

snake game pygame overview 2

For fun, I also turned it into an executable using:

  1. Cx_Freeze (a python module) to turn the python .py script into an .exe program
  2. Inno Setup (free & open source) to turn the .exe program into an installable package (which can then be installed on any computer)

cx_Freeze Primer

Allows you to create a Windows executable file directly given the Python source code

  • python build : Build for any platform
  • python bdist_msi : build for windows 64 bit
  1. install cx_Freeze
  2. create the file. Import cx_Freeze and type anything relevant in it (examples provided)
  3. from the command line: python build - creates a "build" folder
  4. go inside the "build" folder @ build/exe
  5. the executable is in there, you run it from the directory and you transfer the entire directory to wherever you want to run your program

Sample file:

#! python
import os
os.environ['TCL_LIBRARY'] = "C:/Program Files/Python36/tcl/tcl8.6" # or os.environ.get('TCL_LIBRARY')
os.environ['TK_LIBRARY'] = "C:/Program Files/Python36/tcl/tk8.6"
import cx_Freeze

executables = [cx_Freeze.Executable("")]

    name = "Snake",
    version = "0.1",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":["images/apple.png","images/snake_head.png","sounds/crunch.wav", "fonts/CloisterBlack.ttf"]}},
    description = "Snake Game, made with Python + PyGame",
    author = "Name Surname",
    executables = executables


Github repository link.


The image graphics I sketched myself using Adobe Photoshop.
- crunch.wav sound effect from (keyword “crunch”)
- Cloister Black Font is free from Dieter Steffmann at link.