CS177-Lab-Prep-6

request Description:

In this request you will write and submit the labprep6.py program. Complete and submit the file by 11:59
pm on the night before your lab to receive full credit.

Python Graphics Library:

Carefully review the Graphics chapter in the Zelle text (Ch 4) covering this topic and the Python Graphics
library documentation found at: http://mcsp.wartburg.edu/zelle/python/graphics/graphics.pdf before starting Lab
Prep 6. If you haven’t already, download the Graphics module graphics.py from Blackboard. Remember that it
must be in the same folder as labprep6.py

Steps For This request:

  1. Setup your Python file labprep6.py with an appropriate comments header
  2. Organize labprep6.py using comments for each block of planned code
  3. In each block, write the necessary Python code to complete the task
  4. Save, test, then upload your completed labprep6.py Python program to Blackboard

TO DO #1: Setup Your Python Program File labprep6.py

In Python, the # sign indicates a comment, which documents and organizes your code. Python does not
execute these commented lines; they are used to make the program easier to understand. In the Python IDLE
editor, open a new program window. At the top of the file, create a program header by typing in the following
text:

1
2
3
4
5
6
#
# CS 177 – labprep6.py
# {insert your name, and Purdue ID here}
# Following Coding Standards and Guidelines
# {insert a description of the program here}
#

TO DO #2: Organize labprep6.py with pseudo code comments

Plan and comment your program. By now, you should have had enough
practice to writing good, descriptive pseudo code comments for each
section and function.

TO DO #3: The main() Function

Write a Python main() function that takes no arguments and returns no
values. This function should create a Graphics Window, of size 500x500
pixels. Set the background to light grey. Create a red Square (Rectangle
with equal sides measuring 30) in the center of the Graphics Window.
An example is shown in Figure 1.

TO DO #4: Animating the square’s movement

Edit your main() function, so that it now waits for the user to click anywhere within the Graphics window.
Once a mouse click is detected, the red square should move from its current location to the location of the
mouse click.

NOTE: To earn full credit, the square should not disappear and reappear to move across the screen – it must
appear to move smoothly across the window to the mouse click location. An example of this animation is
shown with the Lab Prep 6 request on Blackboard.

HINT: It could be helpful to write a separate function that animates the square which will be called
within the main() function after a mouse click.

The user will be able to click in the Window to move the square five (5) times. After the square reaches the fifth
mouse click location, display a Text object in the center of the Window: “Click to Exit”. One additional
click closes the Graphics window and ends the program without error messages.

Save and Submit your Completed labprep6.py File on Blackboard:

Save your program with the file name labprep6.py, and submit it by 11:59 pm on the night before lab.