This chapter introduces how to create simple graphics and animations using the “Graphics” library by Professor John M. Zelle at Wartburg College. This library interfaces to and simplifies the built in tkinter library.

To use this library you must first download the file graphics.py and place it in the directory where your Python programs will be saved. You may download the open-source file here: http://mcsp.wartburg.edu/zelle/python/ . There is also a manual going into much more detail that can be downloaded here: http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf .

The programs and method for using this module, in this chapter, varies from the original author’s documentation. To maintain consistency between chapters, the graphics module will be imported using an absolute import and not a relative import. The examples will prefix the modules’ classes by the module name ‘graphics’. Using modules this way insures that if two modules have classes or properties with the same names, there will not be a conflict.

Objectives

Upon completion of this chapter’s exercises, you should be able to:

  • Use a coordinate system with the upper left corner at origin.
  • Use the point class to create shapes and to get the coordinate location of shapes on the screen.
  • Draw basic shapes like: circles, squares, rectangles, ovals, and lines.
  • Apply modifications to shapes to change the display of their color and borders.
  • Draw text on the screen in different fonts and sizes.
  • Use a system delay and the move method of shapes to create simple animations.

Download PDF of Chapter