# -*- coding:utf-8 -*- ################################ # excel 表格对比 # ################################ import os import tkinter as tk from tkinter import ttk from tkinter import filedialog, dialog class CompareData: pass class CompareFormat: pass class MainView: def __init__(self, root: tk.Frame): self.__root: tk.Frame = root self.__select_template_file_mess: tk.StringVar = tk.StringVar() self.__select_template_file_mess.set('请选择模版文件') self.__template_file_name: tk.StringVar = tk.StringVar() self.__template_file_name.set('') self.__select_compare_file_mess: tk.StringVar = tk.StringVar() self.__select_compare_file_mess.set('请选择对比文件') self.__compare_file_name: tk.StringVar = tk.StringVar() self.__compare_file_name.set('') self.__conf_type: tk.IntVar = tk.IntVar() # 配置方式 self.__progress: tk.IntVar = tk.IntVar() self.__progress.set(20) def create_windows(self): template_f = tk.Frame(self.__root, bg='gainsboro') template_f.rowconfigure(0, weight=1) template_f.columnconfigure(0, weight=1) template_f.grid(row=0, column=0, padx=5, pady=5, sticky=tk.NW) compare_f = tk.Frame(self.__root, bg='gainsboro') compare_f.rowconfigure(0, weight=1) compare_f.columnconfigure(0, weight=1) compare_f.grid(row=1, column=0, padx=5, pady=5, sticky=tk.NW) compare_type_f = tk.Frame(self.__root, bd=1, height=50) compare_type_f.grid(row=2, column=0, padx=5, pady=5, sticky=tk.NW) start_f = tk.Frame(self.__root, bd=1, height=50) start_f.grid(row=3, column=0, padx=5, pady=5, sticky=tk.NW) scala_f = tk.Frame(self.__root, bd=1, height=50) scala_f.grid(row=4, column=0, padx=5, pady=5, sticky=tk.NW) info_f = tk.Label(self.__root, bg='silver', text='自动判断列名并合并相同列数据') info_f.grid(row=5, column=0, sticky=tk.NSEW) template_f_select = ttk.Button(template_f, state=tk.NORMAL, text="选择模版文件", command=self.__select_template_file) template_f_select.grid(row=0, column=0) template_f_text = ttk.Label(template_f, textvariable=self.__select_template_file_mess) template_f_text.grid(row=0, column=1) compare_f_select = ttk.Button(compare_f, text="选择对比文件", command=self.__select_compare_file) compare_f_select.grid(row=0, column=0) compare_f_text = ttk.Label(compare_f, textvariable=self.__select_compare_file_mess) compare_f_text.grid(row=0, column=1) data_only_rb = ttk.Radiobutton(compare_type_f, variable=self.__conf_type, text='仅对比数据', value=0, command=self.__conf_type_selection) data_only_rb.grid(row=0, column=0, padx=5, sticky=tk.W) format_only_rb = ttk.Radiobutton(compare_type_f, variable=self.__conf_type, text='仅对比格式', value=1, command=self.__conf_type_selection) format_only_rb.grid(row=0, column=1, padx=5, sticky=tk.W) data_format_rb = ttk.Radiobutton(compare_type_f, variable=self.__conf_type, text='对比数据和格式', value=2, command=self.__conf_type_selection) data_format_rb.grid(row=0, column=2, padx=5, sticky=tk.W) start_b = ttk.Button(start_f, state=tk.NORMAL, text="开始", command=self.__start_compare) start_b.grid(row=0, column=0) progressbar = ttk.Progressbar(scala_f, length=200, mode="determinate", orient=tk.HORIZONTAL, variable=self.__progress) progressbar.grid(row=0, column=0, padx=5, sticky=tk.NSEW) def __select_template_file(self): file = filedialog.askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('~/')), filetypes=[('Excel xls', '*.xls')]) if len(file) > 0: self.__select_template_file_mess.set('模版文件:' + file) else: self.__select_template_file_mess.set('请选择模版文件') self.__template_file_name.set(file) def __select_compare_file(self): file = filedialog.askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('~/')), filetypes=[('Excel xls', '*.xls')]) if len(file) > 0: self.__select_compare_file_mess.set('对比文件:' + file) else: self.__select_compare_file_mess.set('请选择对比文件') self.__compare_file_name.set(file) def __conf_type_selection(self): conf_type = self.__conf_type.get() if conf_type == 0: pass elif conf_type == 1: pass elif conf_type == 2: pass def __start_compare(self): pass def main(): root = tk.Tk() root.title('Excel 文件对比工具') root.geometry('720x640') root.minsize(720, 640) root.rowconfigure(0, weight=1) root.columnconfigure(0, weight=1) master_frame = tk.Frame(root) master_frame.grid(row=0, column=0, padx=5, pady=5, sticky=tk.NSEW) w = MainView(master_frame) w.create_windows() root.mainloop() if __name__ == '__main__': main()