def draw_map(cans):
rec_coords = [(410, 50, 470, 65), (100, 150, 170, 165), (330, 150, 410, 165), (260, 250, 320, 265),
(10, 330, 70, 345),(435, 310, 490, 325), (15, 390, 70, 405), (215, 380, 270, 395),
(385, 370, 440, 385),(200, 490, 260, 505), (380, 450, 440, 465)]
text_coords = [(440, 57, "行政大楼"), (135, 157, "计算机学院"), (370, 157, "经济管理学院"), (290, 257, "文理大楼"),
(40, 337, "七号组团"),(460, 317, "图书馆"), (40, 397, "西苑"), (240, 387, "明德楼"),
(410, 377, "笃学楼"),(230, 497, "文体中心"), (410, 457, "材料学院")]
line_coords=[(410,50,170, 150),(410,50,330, 150),(170, 165,330, 150),(135, 165,40, 330),(135, 165,290, 250),
(330, 150, 290, 250),(40, 330, 290, 265),(40, 345, 40, 390),(40, 345, 240, 380),(290, 265,240, 380),
(290, 265,460, 310),(270, 385,385, 375),(240, 380,460, 325),(240, 395,230, 490),(215, 390,70, 400),
(460, 325,410, 370),(410, 385,410, 450),(410, 385,230, 490),(380, 465,230, 490),(40, 405,230, 490)]
for coord in rec_coords:
cans.create_rectangle(coord,width=3,outline="white")
for coord in text_coords:
cans.create_text(coord[0], coord[1], text=coord[2],font=('微软雅黑',10))
for coord in line_coords:
cans.create_line(coord,width=3,fill="white")
def navigate(start, end,campus_map,paths):
global nodes,best_route
if start not in nodes:
messagebox.showerror("提示", "出发地不存在!")
exit()
elif end not in nodes:
messagebox.showerror("提示", "目的地不存在!")
exit()
start, end = nodes.index(start), nodes.index(end)
arrange_path(start,end,campus_map,paths)
messagebox.showinfo("导航结果", "路线:" + best_route + " 总路程:" + str(campus_map[start][end]))
best_route=""
def arrange_path(start, end, campus_map,paths):
global best_route
if start == end:
best_route += nodes[end] + "->"
else:
arrange_path(start, paths[start][end], campus_map, paths)
best_route += nodes[end] + "->"
def build_toplevel5(r):
campus_map = [[0, 400, 100, INF, 180, 300, INF, INF, INF, INF, INF],
[400, 0, INF, INF, INF, 150, 50, 600, INF, INF, INF],
[100, INF, 0, 210, 170, INF, INF, INF, INF, INF, INF],
[INF, INF, 210, 0, 350, INF, INF, INF, INF, 320, 240],
[180, INF, 170, 350, 0, 120, INF, INF, 470, 200, INF],
[300, 150, INF, INF, 120, 0, 300, INF, 380, INF, INF],
[INF, 50, INF, INF, INF, 300, 0, 500, INF, INF, INF],
[INF, 600, INF, INF, INF, INF, 500, 0, INF, INF, INF],
[INF, INF, INF, INF, 470, 380, INF, INF, 0, 100, INF],
[INF, INF, INF, 320, 200, INF, INF, INF, 100, 0, 150],
[INF, INF, INF, 240, INF, INF, INF, INF, INF, 150, 0]]
paths = [[i] * 11 for i in range(11)]
for k in range(11):
for i in range(11):
for j in range(11):
if campus_map[i][j] > campus_map[i][k] + campus_map[k][j]:
campus_map[i][j] = campus_map[i][k] + campus_map[k][j]
paths[i][j] = paths[k][j]
tl = Toplevel(r)
tl.title("导航")
frame1=Frame(tl)
frame1.pack(side="top")
frame2=Frame(tl)
frame2.pack()
tl.geometry("500x650+500+100")
cans=Canvas(frame1,background="pink",height=520,width=500)
cans.pack()
Button(frame1,text="点击显示校园地图", command=lambda:draw_map(cans)).pack()
Label(frame2, text="出发地:").grid(row=0,column=0,pady=5)
Label(frame2, text="目的地:").grid(row=1,column=0,pady=5)
e1 = Entry(frame2)
e2 = Entry(frame2)
e1.grid(row=0,column=1,pady=5)
e2.grid(row=1,column=1,pady=5)
Button(tl, text="确定", command=lambda: navigate(e1.get(), e2.get(),campus_map,paths)).pack()
def destination_info(number):
info=linecache.getline("information.txt", int(number[3]))
messagebox.showinfo("查询结果",info)
def build_toplevel6(r):
tl = Toplevel(r)
tl.geometry("700x550+400+200")
tl.transient()
ima = PhotoImage(file="campus_map.gif")
lb = Label(tl, image=ima)
lb.image = ima
lb.pack()
Label(tl, text="需要查询的比赛室(比赛室1/2/3/4/5/6/7/8/9:").pack()
e = Entry(tl)
e.pack()
Button(tl, text="查询", command=lambda: destination_info(e.get())).pack()
课设——校园导航源码
最新推荐文章于 2024-07-13 23:51:10 发布