The Invent with Python Blog

Writings from the author of Automate the Boring Stuff.

Code Comments Tutorial: Ink Spill - A "Flood It" Clone

Thu 09 September 2010    Al Sweigart

Welcome to the Code Comments Tutorial for Ink Spill. Code Comments is a series of simple games with detailed comments in the source code, so you can see how the game works.

The text in between the triple-double-quotes are comments (technically they are multi-line strings, but Python uses them for multi-line comments). The Python interpreter ignores any text in between them, so we can add any comments about the source code without affecting the program. In general for Code Comments, the comments will describe the lines of code above the comment. It helps to view this file either on the Code Comments site or with a text editor that does "syntax highlighting", so that the comments appear in a separate color and are easier to distinguish from the code.

This Code Comments assumes you know some basic Python programming. If you are a beginner and would like to learn computer programming, there is a free book online called "Invent Your Own Computer Games with Python" at

The Code Comments programs make references to sections of this book throughout the program. This Code Comments can also teach you how to use the Pygame library to make your own games with graphics, animation, and sound. You can download Pygame from and view its documentation.

UPDATE: I've since created a "fancy version" of the game that adds some nice images and variable board sizes and difficulty settings. The zip file can be downloaded below.

Screenshot of Ink Spill game

Screenshot of Ink Spill game

Screenshot of Ink Spill game

Ink Spill source code with comments.

Ink Spill source code without comments.

Ink Spill .exe executable Windows binary (no need to download Python & Pygame)

Fancy version of Ink Spill (source and executable)

How To Play Ink Spill:

Click on the colored palettes at the bottom to change the color of the top left box. Any boxes connected to this box with the same color will also have their color changed. The goal of the game is to turn the entire board to a single color before running out of turns.

Learn to program for free with my books for beginners:

Sign up for my "Automate the Boring Stuff with Python" online course with this discount link.

Email | Mastodon | Twitter | Twitch | YouTube | GitHub | Blog | Patreon | LinkedIn | Personal Site