from tkinter import * from tkinter import filedialog as fd from tkinter import messagebox as mb from math import * from os import path from PIL import ImageTk, Image root = Tk() root.title("TUI2020gimn14") w = root.winfo_screenwidth() # ширина экрана h = root.winfo_screenheight() # высота экрана w = w//2 # середина экрана h = h//2 w = w - 200 # смещение от середины h = h - 200 root.geometry('400x400+{}+{}'.format(w, h)) file_name="dani.txt" def graf(): new = Tk() w=362 h=604 new.geometry('362x604+{}+{}'.format(w//2, 0)) canvas = Canvas(new, height=h, width=w) canvas.pack() background_image=ImageTk.PhotoImage(file ='2.jpg', master= new) #my_image = ImageTk.PhotoImage(file='2.jpg', master= new) canvas.create_image(0, 0, anchor=NW, image=background_image) global t global s global n global m global x,y global smin,tmin,kmin def p(k,v,vv): global t global s global n global m global x,y global smin,tmin,kmin t[k]=v+1 if k>n-2 or v==vv: if v==vv: s=0 for i in range(k): #print(t[i],end=' ') s=s+m[i][i+1] print() if s0: p(k+1,j,vv) print(file_name) f1=open(file_name,'r') f2=open('Finish.txt','w') n=int(f1.readline()) x=list() y=list() t=[0]*n smin=1000000 tmin=[0]*n kmin=n s=0 for i in range(n): x1,y1= map(int,f1.readline().split()) x.append(x1) y.append(y1) m=[0]*n for i in range(n): m[i]=[0]*n #print(m,end='') m1=int(f1.readline()) for i in range(m1): a,b= map(int,f1.readline().split()) l=((x[a-1]-x[b-1])**2+(y[a-1]-y[b-1])**2)**0.5 m[a-1][b-1]=round(l,2) m[b-1][a-1]=round(l,2) v1,v2= map(int,f1.readline().split()) '''for i in range(n): for j in range(n): print(m[i][j],end=' ',file=f2) #print('',file=f2)''' f2.close() f1.close() xmin=0 ymin=0 xmax=10 ymax=10 #print(xmax,ymax) for i in range(n): for j in range(i,n): if m[i][j]>0: #print(i,j,'---',x[i],y[i],x[j],y[j]) #x1=int((x[i]-xmin)/(xmax-xmin)*500) #x2=int((x[j]-xmin)/(xmax-xmin)*500) #y1=int(500-(y[i]-ymin)/(ymax-ymin)*500) #y2=int(500-(y[j]-ymin)/(ymax-ymin)*500) x1=x[i] y1=y[i] x2=x[j] y2=y[j] canvas.create_line(x1,y1,x2,y2,width=5,fill="green") #Пошук #print(v1,v2) p(0,v1-1,v2-1) #print(smin,kmin+1) car = canvas.create_rectangle(x[tmin[0]-1], y[tmin[0]-1], x[tmin[0]-1]+20, y[tmin[0]-1]+20, fill='yellow') for i in range(kmin): #print(tmin[i],end=' ') x1=x[tmin[i]-1] y1=y[tmin[i]-1] x2=x[tmin[i+1]-1] y2=y[tmin[i+1]-1] canvas.create_line(x1,y1,x2,y2, width=3, fill="red") for i in range(kmin): x1=x[tmin[i]-1] y1=y[tmin[i]-1] x2=x[tmin[i+1]-1] y2=y[tmin[i+1]-1] #canvas.create_line(x1,y1,x2,y2, width=3, fill="red") mm=max(abs(x2-x1),abs(y2-y1)) dx=(x2-x1)/mm dy=(y2-y1)/mm while int(dx)!=0 or int(dy)!=0: if x1==x2:dx=0 if y1==y2:dy=0 canvas.move(car, dx, dy) x1=x1+dx y1=y1+dy canvas.after(20) canvas.update() #x1=int((x[tmin[i]-1]-xmin)/(xmax-xmin)*500) #x2=int((x[tmin[i+1]-1]-xmin)/(xmax-xmin)*500) #y1=int(500-(y[tmin[i]-1]-ymin)/(ymax-ymin)*500) #y2=int(500-(y[tmin[i+1]-1]-ymin)/(ymax-ymin)*500) #canvas.move(car, x[tmin[kmin]], y[tmin[kmin]]) #car = canvas.create_rectangle(0, 0, 20, 20, fill='yellow') print() new.mainloop() def insertText(): global file_name try: file_name = fd.askopenfilename(filetypes=(("TXT files", "*.txt"),)) text.delete(1.0, END) with open(file_name) as f: s = f.read() text.insert(1.0, s) except TypeError: mb.showerror("Error", "Choose any file") except FileNotFoundError: mb.showerror("Error", "Indicate file") def extractText(): try: file_name = fd.asksaveasfilename(initialdir= path.dirname('dani/*'), filetypes=(("TXT files", "*.txt"),)) with open(file_name,'w') as f: s = text.get(1.0, END) f.write(s) except FileNotFoundError: mb.showerror("Error", "Indicate file") except TypeError: mb.showerror("Error", "Choose any file") def helps(): url = 'file:///C:/tui2019/help/help1.htm' webbrowser.open(url) def clearText(): #global temp m=mb.askyesno(message="Очистити дані?") def image(): def motion(event): x, y = event.x, event.y r.title(str(x)+' '+str(y)) image = Image.open(file_name) rr, gg, bb = image.getpixel((x, y)) r.title(str(x)+' '+str(y)+" R:"+str(rr)+" G:"+str(gg)+" B:"+str(bb)) r = Toplevel() r.title("My image") try: file_name = fd.askopenfilename(filetypes=(("JPG files", "*.jpg"),)) image = Image.open(file_name) w, h = image.size canvas = Canvas(r, height=h, width=w) canvas.pack() my_image = ImageTk.PhotoImage(file=file_name, master= root) canvas.create_image(0, 0, anchor=NW, image=my_image) r.bind('', motion) except FileNotFoundError: mb.showerror("Error", "Indicate file") except TypeError: mb.showerror("Error", "Choose any file") mainmenu = Menu(root) root.config(menu=mainmenu) menu2=Menu(root, tearoff=0) menu2.add_command(label='Clear',command=clearText) text = Text(width=50, height=25) text.grid(row=0, column=0) filemenu = Menu(mainmenu, tearoff=0) filemenu.add_command(label="Відкрити...",command=insertText) filemenu.add_command(label="Зберегти...",command=extractText) filemenu.add_command(label="Вихід",command=root.destroy) fileimg = Menu(mainmenu, tearoff=0) fileimg.add_command(label="Побудова",command = graf) fileimg.add_command(label="Колір",command = image) helpmenu = Menu(mainmenu, tearoff=0) helpmenu.add_command(label="Допомога",command = helps) mainmenu.add_cascade(label="Файл", menu=filemenu) mainmenu.add_cascade(label="Карта", menu=fileimg) mainmenu.add_cascade(label="Допомога", menu=helpmenu) root.mainloop()