class Mygui():
def __init__(self):
self.window = tk.Tk()
screenwidth = self.window.winfo_screenwidth()
screenheight = self.window.winfo_screenheight()
x, y = int((screenwidth - 400) / 2), int((screenheight - 400) / 2)
#保证在屏幕中间显示
self.window.title('生成器')
self.window.geometry('400x320+{}+{}'.format(x, y))
#使用图标
self.window.iconbitmap(THEPATH +'\\'+'dist\\resizeApi.ico')
#更换背景图片
self.img = Image.open(THEPATH +'\\'+'dist\\images\\background.jpg').resize((400, 320))
global photo
photo = ImageTk.PhotoImage(self.img)
label = tk.Label(self.window,justify=tk.LEFT,image = photo).grid(row=0,column=0)
def arrangement(self):
#设置样式
frame0 = tk.LabelFrame(self.window,text ='配置',bg='#C4E1FF' ,width = 400,height =360)
frame0.place(x=10,y=20)
leida_name = tk.Label(frame0,text = "名称:",bg='#C4E1FF' , height=2,justify = tk.LEFT)
leida_name.grid(row=0,column =0)
self.leida_data = tk.Entry(frame0,width =15,bg ='#FCFCFC')
self.leida_data.grid(row=0,column =1)
leida = tk.Label(frame0,text = "经纬坐标:",bg='#C4E1FF' ,justify = tk.LEFT)
leida.grid(row=0,column =2)
self.leida_posi = tk.Entry(frame0,width =15,bg ='#FCFCFC')
self.leida_posi.grid(row=0,column =3)
leida = tk.Label(frame0,text = "威力参数:", bg='#C4E1FF' ,height=2,justify = tk.LEFT)
leida.grid(row=1,column =0)
self.leida_power = tk.Entry(frame0,text='',width=15,bg ='#FCFCFC')
self.leida_power.grid(row=1,column =1,)
butun0 = tk.Button(frame0,text='选择文件',width=10,bg = '#EFFFD7',height=1,fg='black', padx=1,command = self.filefunc0)
butun0.grid(row=1,column = 2,columnspan=2)
leida = tk.Label(frame0,text = "航线参数:",bg='#C4E1FF' , height=2,justify = tk.LEFT)
leida.grid(row=2,column =0)
self.leida_air = tk.Entry(frame0,text='',width=15,bg ='#FCFCFC')
self.leida_air.grid(row=2,column =1,)
butun1 = tk.Button(frame0,text='选择文件',width=10,height = 1,bg = '#EFFFD7',padx=1,command = self.filefunc1)
butun1.grid(row=2,column = 2,columnspan=2)
leida = tk.Label(frame0,text = "重点区域参数:",bg='#C4E1FF' , height=2,justify = tk.LEFT)
leida.grid(row=3,column =0)
self.leida_area = tk.Entry(frame0,text='',width=15,bg ='#FCFCFC')
self.leida_area.grid(row=3,column =1,)
butun2 = tk.Button(frame0,text='选择文件',bg = '#EFFFD7',width=10,height = 1,padx=1,command = self.filefunc2)
butun2.grid(row=3,column = 2,columnspan=2)
nots = tk.Label(frame0, text="",bg='#C4E1FF' , height=1, justify=tk.LEFT)
nots.grid(row=4, column=0)
butun3 = tk.Button(frame0,text='取消',bg='#D2E9FF',width=15,height = 1,padx=1,command = self.window.destroy)
butun3.grid(row=5,column = 0,columnspan=2)
butun4 = tk.Button(frame0,text='确定',bg='#66B3FF' ,width=15,height = 1,padx=1,command= self.deposit)
butun4.grid(row=5,column = 2,columnspan=2)
nots = tk.Label(frame0, text="", bg='#C4E1FF' ,height=1, justify=tk.LEFT)
nots.grid(row=6, column=0)
def deposit(self):
position = self.leida_posi.get()
position = position.split(',')
name = self.leida_data.get()
data ={'name':name,'location':[float(position[1]),float(position[0])]}
file = open(THEPATH +'\\'+'terminaldata', 'w', encoding='utf-8')
file.write(json.dumps(data))
file.close()
time.sleep(1)
self.destroy()
#添加函数
def filefunc0(self):
filepath = tk.filedialog.askopenfilename(title=u'选择文件')
self.leida_power.insert(0,filepath)
fr = open(THEPATH +'\\'+filepath,'r',encoding='utf-8')
fread=fr.read()
fw = open(THEPATH +'\\'+'威力','w',encoding='utf-8')
fw.write(fread)
fr.close(),fw.close()
def filefunc1(self):
filepath = tk.filedialog.askopenfilename(title=u'选择文件')
self.leida_air.insert(0,filepath)
fr = open(THEPATH +'\\'+filepath,'r',encoding='utf-8')
fread=fr.read()
fw = open(THEPATH +'\\'+'航线','w',encoding='utf-8')
fw.write(fread)
fr.close(),fw.close()
def filefunc2(self):
filepath = tk.filedialog.askopenfilename(title=u'选择文件')
self.leida_area.insert(0, filepath)
fr = open(THEPATH +'\\'+filepath, 'r', encoding='utf-8')
fread = fr.read()
fw = open(THEPATH +'\\'+'重要区域', 'w', encoding='utf-8')
fw.write(fread)
fr.close(), fw.close()
def destroy(self):
self.window.destroy()
def mailoop(self):
self.window.mainloop()