""" rectangles.py In class working out the draw rectangles and read in data from file assignment. """ from graphics import * window = GraphWin("rectangle homewwork", 400, 300) # x is going to have 5 names, so coords 0 to 6 # (1,2,3,4,5) for rectangle positions # y is going from (say) 0 to 110. # so coords from -10 to 120 window.setCoords(0, -10, 6, 120) # read in data from file # For now, I'll just define ## names = ['Jim', 'Joe', 'Jane', 'Mary', 'Sam'] ## y = [30, 100, 20, 50, 40] file = open("data.txt") lines = file.readlines() names = [] values = [] for line in lines: (name, y) = line.split(',') # print " name is '" + str(name) + "'" # print " y is '" + str(y) + "'" # print names = names + [name] values = values + [int(y)] # print "names = " + str(names) # print "values = " + str(values) for i in range(5): name = names[i] value = values[i] rectangle = Rectangle(Point(i+1,0), Point(i+2,value)) rectangle.draw(window) label = Text(Point(i+1.3, -5), name) label.draw(window) print "Click somewhere" click = window.getMouse() print "You clicked at (" + str(click.x) + "," + str(click.y) + ")" wait = raw_input("OK? ")