1 # encoding:utf-8
2
3 from tkinter import *
4 from tkinter import messagebox
5 from tkinter import filedialog
6
7 '''
8 画图形界面,供user操作
9 界面功能:
10 1.USER选择类型:BC1,MBM
11 2.USER导入EXCEL
12 3.点击数据处理,生成处理后的excel
13 '''
14
15 class OpenMyXLS(Frame):
16 def __init__(self, master=None):
17 super().__init__(master)
18 self.master = master
19 self.pack()
20 self.openxls()
21
22 def openxls(self):
23 #创建一个标签:请选择数据处理类型
24 self.lab1 = Label(root, text="请选择要处理的数据类型:", font=("Arial", 12))
25 self.lab1.place(x=30, y=30)
26 #创建两个单选框:BC1,MLB
27
28 self.var = StringVar()
29 self.strPath = StringVar()
30 self.var.set("BC1")
31 self.radb1 = Radiobutton(root, text='BC1', value="BC1", variable=self.var, command=self.songhua)
32 self.radb1.place(x=30, y=60)
33 self.radb2 = Radiobutton(root, text='MBM', value="MBM", variable=self.var, command=self.songhua)
34 self.radb2.place(x=90, y=60)
35 #创建一个文本选择框(文本,输入框,按钮)
36 self.lab2 = Label(root, text="xlxs格式:", font=("Arial", 12))
37 self.lab2.place(x=30, y=90)
38 self.ent = Entry(root, width=40, textvariable=self.strPath)
39 self.ent.place(x=110, y=90)
40 self.bt1 = Button(root, text="选择文件", font=("Arial", 12), width=10, height=1, command=self.pathCallBack)
41 self.bt1.place(x=400, y=85)
42
43 # 选择文件夹
44 #Folderpath = filedialog.askdirectory()
45 # 选择文件
46 #Filepath = filedialog.askopenfilename()
47 # 打印文件夹路径
48 #print('Folderpath:', Folderpath)
49 # 打印文件路径
50 #print('Filepath:', Filepath)
51
52 #创建一个按钮:开始处理数据
53 self.bt2 = Button(root, text="开始数据处理", font=("Arial", 12), width=20, height=2)
54 self.bt2.place(x=180, y=120)
55 #创建一个提示信息:显示处理后的文档位置
56 self.lab3 = Label(root, text="提示信息!", font=("Arial", 12))
57 self.lab3.place(x=30, y=180)
58 return None
59
60 def songhua(self):
61 messagebox.showinfo("信息选择", "你想要处理的数据是:"+self.var.get())
62
63 def pathCallBack(self):
64 filePath = filedialog.askopenfilename(title="Select excel file", filetypes=(("excel files", "*.xlsx"),))
65 if (filePath != ''):
66 self.strPath.set(filePath)
67
68 if __name__ == '__main__':
69 root = Tk()
70 root.geometry("500x300+200+300")
71 root.title("81 mapping 70 数据处理小程序")
72 app = OpenMyXLS(master=root)
73 root.mainloop()