from Tkinter import * from sys import exit from random import choice # OR LIKE THIS: colors="red green blue purple".split() colors=["red", "green", "blue", "purple"] Color={'PENTAGON1': 'green'} # THIS VERSION IS ONLY COLORING ONE POLYGON w,h=800,600 minX=0 minY=0 maxX=160 maxY=100 root=Tk() canvas=Canvas(root,width=w,height=h,bg="yellow") canvas.pack() # read the polygon filelines=open("pentagonSample.csv").read().split('\n')#[1:-1] print "filelines=%s" % filelines filelines=filelines[1:-1] # remove the first and last lines print "filelines=%s" % filelines polygonlocations={} for i in range(0,5): # 5 lines contatining data points for the pentagon line=filelines[i] linedata=line.split(',') print "%d: %s" % (i,linedata) polygonname = linedata[0] xloc = linedata[1] yloc = linedata[2] # or: polygonname,xloc,yloc=line.split(',') print "shape=%s, xloc=%s, yloc=%s" % (polygonname,xloc,yloc) if polygonname not in polygonlocations: polygonlocations[polygonname]=[] xloc=float(xloc) yloc=float(yloc) polygonlocations[polygonname].append((xloc,yloc)) print "Final polygonlocations=%s" % polygonlocations col={} # assign colors for polygon in polygonlocations: col[polygon]=Color[polygon] # draw map for polygon in polygonlocations: xy=[] for (x,y) in polygonlocations[polygon]: xy.append((w*(x-minX)/(maxX-minX),h-h*(y-minY)/(maxY-minY))) canvas.create_polygon(xy,fill=col[polygon],outline="white") root.bind('', lambda e: exit(0)) root.mainloop()