CSci 157 - Lab 5

Purpose: the main objective is to learn how to use selection statements and the graphics module.

Warmup Questions. We'll work through these together; you don't need to write these out.

  1. What method(s) might you use to change the size or font of a Text object?
  2. How can we display images (for example, photos) in a program?
  3. How do we determine when the mouse is clicked on a specific region of the canvas, or in a graphical object such as a Circle or Rectangle?


Like last week, wait until I've assigned pairs before starting on this lab.

Part I
. Create a program vote.py which will use mouse clicks to determine which of two candidates the user of the program prefers. Candidates don't have to be politicians; you could be choosing the favorite of two songs, dogs vs. cats, Coke vs. Pepsi, Sewanee eateries, Super Bowl teams...whatever.

The program will have the following features:

Demonstrate your program to the instructor.


Part II.  Switch driver and observer.

Modify the existing program as described below. The primary changes are to 1) determine users's preference by detecting clicks in an image, and 2) add visual interest. See this program for an example of loading and displaying images. You'll need these two images downloaded in the same directory to run it: image1, image2.

In order to use images, place the image files in the same directory with your program files (later we'll relax this requirement).

As noted below, only a few graphics image formats are supported (GIF, PPM, PNG all work for me).

Demonstrate your program to the instructor.

An example from previous years:

GibsonMolder