Chapter 6. Drawing an Application

We are now on to developing our last major Tkinter application. In this project, we will develop a drawing application, making extensive use of the Tkinter Canvas widget while applying everything else that we have learned so far.

Mission Briefing

Our drawing program will enable the user to draw basic shapes such as lines, circles, rectangles, and polygons. It will also let the user draw with the brush tool using different colors that can be chosen from the color palette.

In its final form, our drawing program will look like the following screenshot:

Mission Briefing

Why Is It Awesome?

While the application itself is rudimentary, it is sufficient to demonstrate some important aspects related to GUI programming.

This project aims to drive home two important lessons. First, we will experience the power of the Canvas widget. Second, we will learn how to develop higher-level custom GUI frameworks for our applications.

As we shall see, custom GUI frameworks enable us to develop programs rapidly with minimal amount of code repetition.

By the end of this project, you should not only be in a position to extend this application to add many more features, but you should also be able to take up and implement GUI projects of increasing complexity.

Your Hotshot Objectives

The key learning objectives for this project can be outlined as follows:

  • Learning to build custom GUI frameworks for rapid application development
  • Writing small unit tests for our code
  • Understanding how to use inheritance in our projects
  • Getting to know of other Tkinter modules, such as tkColorChooser
  • Creating and manipulating items on the Canvas widget
  • Working with the tk ComboBox widget
  • Getting to know the available winfo methods
  • Working with mouse events on the Canvas widget
  • Reinforcing things that we have learned in previous projects

Mission Checklist

If you have developed the game of chess, you might have installed the Python Imaging Library (PIL) to render PNG files. This is the only external dependency for our program. If you haven't already done so, download and install PIL from:

http://www.pythonware.com/products/pil/

If you are working on windows x64 (64 bit) or MacOSX machine, you may instead need to install and work with Pillow, which is a replacement for PIL available at:

http://www.lfd.uci.edu/~gohlke/pythonlibs/#pillow

After you have installed the package, go to your Python interactive prompt and type:

>>from PIL import ImageTk

If this executes without any error messages, you are ready to make our drawing application.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.97.202