使用tkinter的美利坚合众国的地图

时间:2018-01-05 21:25:21

标签: python tkinter

我有一个文件,其中包含所有美利坚合众国的所有经度和纬度。每个州都用其邮政缩写表示。 END_ONE_POLY表示结束单个多边形。 END_ALL_POLY表示结束状态的整个多边形。像这样:

    -88.1665689999999955 30.2492550000000016
    -88.1884692736000062 30.2469340542000005
     END_ONE_POLY
     END_ALL_POLY
     AR
    -94.4760497582000056 36.4993199124999990
    -94.4568835367000048 36.4993666550000029

我的任务是创建一张美国地图。这是我的代码:

from Tkinter import Tk,Canvas
from PIL import Image,ImageTk
root = Tk() # Create a window.
canvas = Canvas(root, width=640, height=480, bg="white")

data = open("lab313.txt", "r").read().split()
usamain = []
usaisland = []
usa = []
i = 0
makePoly = False

while True:
   if len(data[i]) == 2 and makePoly == False:
      data.remove(data[i])
      makePoly = True
   if data[i] == "END_ONE_POLY":
      data.remove(data[i])
      makePoly = False
   if makePoly == True:
      usamain.append(float(data[i]))
   if data[i] == "END_ALL_POLY":
      data.remove(data[i])
      data.remove(data[i])
      usamain[:] = []
      usaisland[:] = []
      i = 0
      makePoly = False
   if data[i] == "END_FILE":
      break
   if makePoly == False:
      usaisland.append(float(data[i]))
   usa.append(float(data[i]))

   i += 1

i = 0
print usamain
print usaisland
print usa
canvas.pack()
root.mainloop()

但是,我收到了两个错误:

File "Lab14-1.py", line 17, in <module>
if len(data[i]) == 2 and makePoly == False:
IndexError: list index out of range

File "Lab14-1.py", line 17, in <module>
if data[i] == "END_FILE":
Index Error: list index out of range

我将如何解决此问题。任何反馈都将不胜感激

0 个答案:

没有答案