
Download pyganim.py and example programs. (Works on both Python 2 and 3.)
Details at http://inventwithpython.com/pyganim/
Pyganim is a module that you can import into your Pygame games to handle sprite animation. Creating an animation is simply a matter of supplying a list of image filenames (or pygame.Surface objects) for each frame of animation, along with the duration that each frame lasts. Then call the play() method to start the animation and then call blit() each time you draw the window. The blit() function automatically draws the correct frame based on the amount of real time that has passed since the play() method was called. There are many, many other methods to provide finer levels of control as well.
There is more information available on the Tutorial and Reference page.
Posted by Al Sweigart at 6:20 pm on December 9th, 2011.
Categories: Blog.
I’ve written a book on Python programming for kids and complete beginners. I’ve also done some classroom and one-on-one teaching with adults and teens. I have them use IDLE, the IDE that comes with Python, because it is simple and easier than having them set up some other IDE (like PyDev on Eclipse).
But over time I’ve noticed a lot of problems with IDLE that I wish someone would fix. (I’d like to do it myself but I don’t have the time currently.) I’m very, very grateful that Python comes batteries included vis-à-vis an IDE, but there are a lot of warts and user interface issues with IDLE. (These are different from the bugs listed on the python.org bug tracker.)
First off, my philosophy is that no serious Python programmer uses IDLE as their dev environment. With that assumption, we can get rid of any need to cater to them and make IDLE aimed at people who are not only new to Python but new to programming in general. IDLE should be an education tool more than a development tool. This means that the IDLE default options should all be set for the basic user, not the power user.
With that in mind, these are things I’d like to see changed about the design of IDLE (roughly in order of importance and prior
More… »
Posted by Al Sweigart at 11:08 am on November 29th, 2011.
Categories: Blog.
Here are a couple games I wrote. The first was so popular that I made a sequel:
Win32 EXEs and source:
Look At This Rock
Look At This Rock 2: A Different Rock
Source (requires Pygame to be installed along with Python):
Source: LookAtThisRock.py and PNG
Source: LookAtThisRock2.py and PNG
Screenshots:


Posted by Al Sweigart at 12:03 pm on October 21st, 2011.
Categories: Uncategorized.
Here’s the introductory chapter to my next book on Python and Pygame. It assumes you have some Python and programming experience (if you don’t, give a look to Invent with Python), and offers a quick view of all of the major parts of Pygame.
The chapter by itself is a good introduction to Pygame. If you’ve been meaning to give Pygame a look, then download the chapter. Please email in any questions or suggestions you have: al@inventwithpython.com
Unfortunately, the links in the book aren’t working yet, but should be in a few days.
Posted by Al Sweigart at 9:57 am on October 21st, 2011.
Categories: News, Tutorials.
Yuanle Qiu has started translating the “Invent Your Own Computer Games with Python” into Chinese. The first three five chapters are done, with more on the way. Thanks a lot Yuanle!
If you or someone you know can participate in translating “Invent with Python” into other languages (Hindi, Spanish, French, German, etc.) please contact Al for more information. “Invent with Python” is released under a Creative Commons license, so the translated works would be freely available to those who want to learn programming.
Posted by Al Sweigart at 3:44 pm on October 16th, 2011.
Categories: News.
If you already know a bit of programming and Python, and want to get up to speed on the Pygame 2D game framework, here’s a cheat sheet that you can look over. It implements a very short Pygame program covering most of Pygame’s basic features.
View the Pygame Cheat Sheet.

You can also download the Pygame program itself, along with the cat.png and bounce.wav files it uses. You will need to install Python and Pygame first to run this program. The program looks like this when you run it:

Posted by Al Sweigart at 10:00 am on October 7th, 2011.
Categories: Tutorials.
(UPDATE: I’ve discontinued this sale, but I’ll leave this post up for the record. If you are an educator and would like to buy discount copies of the book, feel free to email me for a discount code.)
I’m putting a sale on hard copies of the “Invent Your Own Computer Games with Python” book until the end of this Saturday. The discount is 55.6% (the max discount I can apply that brings my royalty down to $0.00 for each copy sold) which brings the price of the book to $11.11. To buy a hard copy of the book with this discount, use the following link and discount code:
https://www.createspace.com/3430836
Discount code: E4VHZFT5
The book is, of course, available online in full for free as HTML or a PDF.
Textbooks and tech books (especially geared towards young adults) are ridiculously overpriced. I put “Invent with Python” at $25 to put it within reach of kids (and adults) who want to buy it for themselves (and $25 would qualify it for free shipping on Amazon). Programming is a fun, creative skill to learn, and I’d like to be able to put it in the hands of a few more people with an additional discount.
Hey! Listen! If you’ve read the book before and liked it (or even hated it), the absolute best thing you could do to help me out (moreso than buying a copy) is writing a review on Amazon.
Also, if you are an educator or would like to buy single or bulk copies of this book at this price in the future, email me for the discount code at al@inventwithpython.com.
Posted by Al Sweigart at 11:04 am on October 5th, 2011.
Categories: News.
I wrote some programs to go through 6 GB of OpenStreetMap data from http://metro.teczno.com so that I could extract a list of street names for an upcoming game project. The game will use procedural generation to create cities, so I need to have a dataset of street names but couldn’t easily find one. So I’ve created this one and wanted to share it.
I did a lot of tweaking to remove duplicates. Each street name is on its own line, and you can just add “Rd”, “St”, “Ln”, “Ave”, “Blvd”, “Pkwy” or any other suffix to the end of it. The zip file has a file of street names from each city, and then an allstreets.txt that has all of them combined into one file (with duplicates removed). Streets with numbers have been removed (there is no “7th” but there might be “Seventh”).
The street data comes from Boston, Chicago, Leeds, London, Manchester, St. Paul, New York, Seattle, the San Francisco Bay Area, Sydney, and DC, so you can expect that they mostly have Anglo names.
Then after looking at the data for a while, I realized that these could also be used for Anglo last names. I’ve removed any words that appear in a dictionary file I have, so some common last names like “Smith” or “Hunting” won’t show up. I would consider this list of moderate quality. Here’s the list:
I can’t vouch for the quality of the lists, but from a cursory inspection they seem quite serviceable. Enjoy!
Posted by Al Sweigart at 10:00 am on September 28th, 2011.
Categories: Blog.
I’ve created a web version of the Caesar Cipher wheel using JQuery and CSS sprites.
JavaScript Cipher Wheel

I also have a Pygame version and Windows executable of this.
Posted by Al Sweigart at 10:19 pm on September 20th, 2011.
Categories: Uncategorized.
The Caesar Cipher Wheel is a paper cutout that can be used to perform encryption and decryption in the Caesar Cipher. However, if you don’t have a printer but do have Python and Pygame installed, you can use this Caesar Cipher Wheel program to rotate a virtual cipher disk instead.
Download source and image files. (88 KB)
Download the executable for Windows (5.3 MB)

You will need Python (2 or 3) and Pygame installed to run the program. Or, if you are running Windows, you can download the win32 binary.
Posted by Al Sweigart at 7:54 pm on September 18th, 2011.
Categories: Games.