For the first time recently I built a program from scratch using Python. This was really the first time I have ever done anything serious using Python other than some simple ‘Hello World’ apps or things on CodeCademy so it started me thinking on a couple of projects that I had started quite a while back and I decided to revive one. I chose to revive a little program I called ‘Music Game’ that I started to build for my daughter a while back. Well, it’s not really a music game so much as a game that just makes noises…

I started writing this program to run on my RaspberryPi, I chose this so I could connect it to my TV and take up as little room as possible. Running on the Pi is what led me to start building it in Python in the first place, it was already installed and already had the Pygame libraries loaded for playing sounds and drawing images to the screen.

I started by reading some documentation on the Pygame website about playing sounds and drawing images to the screen. The concept of drawing to the screen in Pygame is pretty simple, you simply call the pygame.draw.rect() function. Once I had the program drawing a rectangle on the screen, I then setup the game loop to draw a rectangle in a random place on the screen whenever any key is pressed. That worked out well for a little while but soon after the first time I let Natalie use it, it became obvious to me that I need to clear the screen periodically. So I made a minor change to the event loop to look for when the escape key is pressed.

The current version of the app plays two sounds, the typewriter clicking sound on all buttons except for the backspace, that button plays a ding sound. It also draws either a circle or a square to the screen in a random location on every key press. I’m thinking about updating the app to allow me to change some settings remotely without having to restart the app. I’m not sure how I’m going to do this yet, but I’ll be sure to make a post as soon as I get something working!

I’ve added the source for the music game to my Github site here: