I'm supposed to create a menu that will give the user options to open and close a file called shapes.txt that opens a file of a bunch of shapes drawn using graphics.py. This is the example we're given but im not sure what to do. When the user types in the name of the shapes file its supposed to open up a window with all of the shapes i've drawn in shapes.txt.
I'm supposed to create a menu that will give the user options to open and close a file called shapes.txt that opens a file of a bunch of shapes drawn using graphics.py. This is the example we're given but im not sure what to do. When the user types in the name of the shapes file its supposed to open up a window with all of the shapes i've drawn in shapes.txt.
from graphics import *
import os
import sys
WINDOW_WIDTH=600
WINDOW_HEIGHT=600
def main ():
# in document, specify the default width and height
win = GraphWin("", WINDOW_WIDTH, WINDOW_HEIGHT)
win.setCoords(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT) # bigger than GraphWin size = zoom out, smaller = zoom in
# ask user for the name of the shapes file
# this is where you would read the shapes file and store the information
# i recommend storing the shape properties in a dictionary
# i recommend storing the shapes in a list
# this is where you would draw the shapes
# i recommend creating a separate function to draw each shape
# drawing a circle
s = Circle(Point(100,100), 100) # Point is created with x,y position for center of circle, then the radius
s.setFill("red")
s.draw(win)
# now a rectangle
s = Rectangle(Point(200,200), Point(300,300))
s.setFill("blue")
s.draw(win)
# pause the program so the graphics window will stay visible
input ("Hit return key to exit the program")
win.close()
# this insures that if you run the program from the command line, it will call the
# main function, e.g.
# python graphics_example.py
if __name__ == "__main__" :
main()
Step by step
Solved in 3 steps with 4 images