Comp 151 Project 3

Simple GUI based adding machine

Summary:

In this third project you will build me a simple adding machine using the Zelle graphics library

Due:

  Sunday Oct 7th at 11:59pm. (you have about a week and a half.)


Description:

First create a new project (which creates a new project folder)

Then  get the Zelle graphics library and put it in your project folder

Then create a window that looks basically like the one below:

what the window looks like when program is first run


After your program gets this window up, you need to loop forever (while True:)


wait for the user to click the mouse,

the project after pressing the add button


To make your life a little easier, you can use the function below to help you determine if one of the fake buttons is pushed (and do nothing if the mouse is clicked outside of those fake buttons).

def is_clicked(rect:graphics.Rectangle, point:graphics.Point):
xloc = point.getX()
yloc = point.getY()
button_width = abs(rect.getP1().getX() - rect.getP2().getX())
button_height = abs(rect.getP1().getY() - rect.getP2().getY())
center = rect.getCenter()
if xloc >= center.getX()- button_width/2 and xloc <= center.getX() + button_width/2 and \
yloc >= center.getY() - button_height/2 and yloc <= center.getY() + button_height/2:
return True
else:
return False


Just paste the function in your code above your def main(): line.



For the example below, assume that click_loc is initialized as follows:

click_loc = window.getMouse()

and clear_rect is the graphics.Rectangle object that I used  to draw it up above. Then can use this in_clicked something like the following:

if is_clicked(clear_rect, click_loc):

Additional  requirements:

Your code must be commented


To help me identify your work, make the name of your program file

yourFirstInitialLastNameLab2.py

(so mine would be JSantoreLab2.py)
And put the following at the beginning of the program as a comment:


Project Submission


Submit your project via blackboard.