10.读取点坐标文件并连线
点坐标文件:
(X Y FLAG)
FLAG=B 表示为线起点
FLAG=M 表示为中间点
FLAG=E 表示为线终点
10.00 10.00 B
10.00 100.00 M
50.00 200.00 M
180.00 50.00 E
500.00 500.00 B
600.00 500.00 M
720.00 820.00 E
代码:
from tkinter import *
canvas = Canvas(width = 1000, height = 1000, background = "white")
canvas.pack(expand=YES, fill=BOTH)
list_x = []
list_y = []
list_flag = []
fp = open("point.txt","r")
line = fp.readline()
flag0 = 0
while line:
s0 = line.split(" ")
list_x.append(float(s0[0]))
list_y.append(float(s0[1]))
list_flag.append(s0[2])
flag0 += 1
line = fp.readline()
i0 = 0
while i0 < flag0:
x1 = list_x[i0]
y1 = list_y[i0]
x2 = list_x[i0 + 1]
y2 = list_y[i0 + 1]
canvas.create_line(x1,y1,x2,y2,activedash=30)
if(list_flag[i0 + 1] == "E"):
i0 += 1
i0 += 1
mainloop()
fp.close()
结果: