Follow these instructions on your local computer to start writing graphical programs.
""" Lab 2E: This program draws a square and a circle and computes their areas. Author: _____________ """ from graphics import * import math def main(): # Draw the graphics window win = GraphWin("Lab 02e", 800, 800) # Draw the prompt to the user, centered near the top of the screen prompt = Text(Point(400, 50), 'Enter a number:') prompt.setSize(18) # 18-point font prompt.setTextColor('black') # just an example; black is the default prompt.draw(win) # Draw the text box for the user to type in, # centered just under the prompt and 20 characters long entry_box = Entry(Point(400, 100), 20) entry_box.draw(win) # Draw the button for the user to click button = Rectangle(Point(375, 175), Point(425, 225)) button.setFill('gray') button.draw(win) # Draw the "OK" in the button button_text = Text(Point(400, 200), 'OK') button_text.setSize(18) button_text.draw(win) # Wait for the user to click on the button clicked_point = win.getMouse() # wait for a click click_valid = False while not click_valid: # see if the click was actually on the button if 375 <= clicked_point.getX() <= 425 and 175 <= clicked_point.getY() <= 225: click_valid = True else: clicked_point = win.getMouse() # wait for a new click ##### CHANGE THE AREA CALCULATIONS ###### length = float(entry_box.getText()) # what the user typed square_area = 0 circle_area = 0 ############################## ##### CHANGE THE COORDINATES OF THE SQUARE'S CORNERS ##### ##### Hint: they should be expressions involving the length variable ##### sq_top_left = Point(0, 0) sq_bottom_right = Point(200, 200) ############################## square = Rectangle(sq_top_left, sq_bottom_right) ##### Optional: Change the colors of the square ##### square.setOutline('red') square.setFill('yellow') square.draw(win) # Display the calculated area area_message = Text(Point(400, 725), 'The area of the square is ' + str(square_area) + '.') area_message.setSize(18) area_message.setTextColor('black') # just an example; black is the default area_message.draw(win) # Display message about how to get the circle bottom_prompt = Text(Point(400, 750), 'Click anywhere in this window to draw the circle.') bottom_prompt.draw(win) win.getMouse() ##### CHANGE THE CIRCLE'S CENTER AND RADIUS ##### circle_center = Point(0, 0) radius = 200 ############################## circle = Circle(circle_center, radius) ##### Optional: Change the colors of the circle ##### circle.setOutline('red') circle.setFill('yellow') circle.draw(win) # Show the area of the circle instead of the square area_message.setText('The area of the circle is ' + str(round(circle_area, 3)) + '.') # Display message about how to exit bottom_prompt.setText('Click anywhere in this window to exit.') # Leave the window open until the user clicks in it, then close win.getMouse() win.close() main()