CS 251: Assignment #1

Building a GUI in Python

For this assignment, you will create a graphical user interface [GUI] using python and the Tkinter library. We'll go over the main concepts in class, but they're also laid out for you here. You'll be building your system on top of this program throughout the semester, so take time to comment the code and make sure you understand it.


Tasks

Before you begin, download the skeleton python file for creating a window and menus using the Tkinter package. Rename the file to display.py or something you like. To run the program, open a Terminal and type the following command.

python display.py

If you're not yet comfortable with Python, there are python books in the Safari Online collection. Work through a few examples so you get a sense for how it works.

There are a number of useful tutorials and documentation sites on Tkinter. You should go through a few of them before continuing with the rest of the assignment.

  1. Modify the function that handles button 1 to draw a cross when you click with the left mouse button on the screen. Store all of the click locations and the lines that you create in lists in your application.
  2. Have the system scroll the lines so they follow the mouse when you click and drag. Note that you can get the coordinates of any item you draw on the Canvas using the coords function. You can also give any item a new location using the coords function.
  3. Remove the dummy command menu options and add a menu function that lets you draw a line between two points where the user clicks. Even though you'll be using the same button1 callback, don't draw crosses when the user is creating a line. You'll need to make a state variable in your application that gets set when the user selects the menu command and then gets modified for the next two clicks until the user has selected the endpoints of the line. Inside your button1 callback, you'll need to use the state variable to decide what should be done on each mouse click. The lines you create should still scroll whenever the user clicks and drags the left mouse button.
  4. The Open... command in the file menu asks the user to select a file, but does nothing with it. Using this file, have your program make circles at each location given in the file. Each row has two numbers on it that are the x and y coordinates for where to draw the circle. The circles do not have to scroll when you click and drag, but it is the first extension.

Extensions


Writeup

The writeup for each weekly project should be a brief summary of what you did along with some screen shots, graphs, or tables of results, depending upon the assignment. Please organize the writeup as follows.

  1. Title of the project and your name
  2. An abstract describing what you did in 200 words or less.
  3. A brief description of code you wrote or analysis you undertook for the project.
  4. Figures, screen shots, graphs, tables, or other results.
  5. A brief description of what you learned.

Handin

Make your writeup for the project a wiki page in your personal space. If you have questions about making a page, stop by during office hours 1-3pm on Mondays or Tuesdays.

Once you have written up your assignment, give the page the label:

cs251s09project1

You can give any page a label when you're editing it using the label field at the bottom of the page.

Do not put code on your writeup page or anywhere it can be publicly accessed. To hand in code, attach it to an email and send it to the prof.