Homework 3: GUIs

Due Wednesday, 2012-04-18, 11:59pm

In this homework, you will practice GUI programming, using Tkinter. You will first need to download hw3_320.py. You will edit this file and submit the result; call it <lastname>_hw3.py. Remember to include your name and the assignment number in a comment at the top of the file and to use lots of comments in your code, including docstrings for all functions that you define.

The world

The world this time consists of a torus, a doughnut-shaped object that wraps around to the left and right and from top to bottom. That is, there aren't any walls that stop things from moving in whatever direction they're heading. The only kinds of things in the world are diskoids, which are round, yellow creatures that can turn and move. They get hungry with time and search for food, the distance traveled depending on their hunger. The only food is available in the "fertile square" located in the dark green region between coordinates (0,0) and (100,100) in the world. When they reach this region, their hunger decreases, so they tend to stay there for some time.

There are three classes in the program: WorldFrame, a subclass of the Tkinter Frame class; World, a subclass of the Tkinter Canvas class and also the class that keeps track of things in the world; and Diskoid, the class that defines the diskoid objects.

What you have to do

In its initial form, the program just creates a frame and a canvas inside it. There are no diskoids in the world. You will need to add three buttons and make them have particular effects and to make the canvas respond to mouse clicks with modifier keys.

  1. Make the canvas respond to mouse clicks.
  2. Add three buttons, arranged horizontally underneath the canvas. The text on the buttons should be "Step", "Run", and "Clear". The buttons should have the following effects when the user clicks on them.
    1. The "Step" button calls the World method step, causing each of the diskoids to execute its step method once.
    2. The "Run" button calls the World method run, causing step to be called 100 times.
    3. The "Clear" button calls the World method clear, removing all of the diskoids from the world.

Home

Calendar

Procedures

Notes

Code

Resources


IU | CogSci

Contact instructor