import tkinter as tk
from tkinter import scrolledtext
from tkinter.filedialog import askdirectory
from tkinter import simpledialog
import tkinter.filedialog
import os,sys
window = tkinter.Tk()
window.title('文件加密工具GUI界面')
window.geometry('400x320')
import subprocess
VarFileName=[]
VarDstdir="c:/"
VarPasswd=""
###=======函数区域========
def choose_fiel():
selectFileName = tk.filedialog.askopenfilenames(title='选择文件') # 选择文件
global VarFileName
VarFileName=selectFileName
e_entry.delete(1.0,tk.END)
# e_entry.insert('insert',selectFileName )
for one in VarFileName:
VarDstdir1=one
e_entry.insert('insert',one + "\n" )
##选择生成目录函数
def choose_dstdir():
selectFileName = askdirectory(title='选择输出目录')
global VarDstdir
VarDstdir=selectFileName
dstdirvar.set(selectFileName)
##加密处理函数
def encrypt_button_fun():
if (VarPasswd == "") :
input_passwd()
out_entry.delete(1.0,tk.END)
for one in VarFileName:
#out_entry.insert('insert',one + "\n" )
#pipeline = os.popen()
command01=sys.path[0].replace('\\','/') + "/%s -key %s -f %s -t %s \n " %("aw1038c-EncrypZipTools.exe" , VarPasswd, one ,VarDstdir +"/" + os.path.basename(one)+ ".ez")
#stdin ,stdout,stderr = os.popen(command01 )
status=os.system(command01 )
if status == 0 :
out_entry.insert('insert', "成功:" +one +"->"+VarDstdir +"/" + os.path.basename(one)+ ".ez" + "\n")
else:
out_entry.insert('insert', "失败:" +one +"->"+VarDstdir +"/" + os.path.basename(one)+ ".ez" + "\n")
##解密处理函数
def decrypt_button_fun():
if (VarPasswd == "") :
input_passwd()
out_entry.delete(1.0,tk.END)
for one in VarFileName:
#out_entry.insert('insert',one + "\n" )
#pipeline = os.popen()
command01=sys.path[0].replace('\\','/') + "/%s -key %s -x -f %s -t %s \n " %("aw1038c-EncrypZipTools.exe" , VarPasswd, one ,VarDstdir +"/" + os.path.splitext(os.path.basename(one))[0] )
print(command01)
#stdin ,stdout,stderr = os.popen(command01 )
status=os.system(command01 )
if status == 0 :
out_entry.insert('insert', "成功:" +one +"->"+VarDstdir +"/" + os.path.splitext(os.path.basename(one))[0] + "\n")
else:
out_entry.insert('insert', "失败:" +one +"->"+VarDstdir +"/" + os.path.splitext(os.path.basename(one))[0] + "\n")
def input_passwd():
global VarPasswd
r = simpledialog.askstring('密码输入', '请输入密码', initialvalue='password')
if r:
VarPasswd=r
print(r)
def on_click():
global UserName
if len(UserName) == 0:
print("用户名必须输入!")
exit()
window.quit()
window.destroy()
print("用户名:%s" %(UserName))
#选择文件
submit_button = tk.Button(window, text ="选择文件", command = choose_fiel )
submit_button.pack()
#文本框
e_entry = scrolledtext.ScrolledText(window ,height=4 )
e_entry.pack()
#设置文件生成目录
dstdirvar = tk.StringVar() #设置文件生成目录变量
dstdirvar.set('c:/' )
Labeldstdir = tk.Label(window, textvariable=dstdirvar ,font=('Arial', 12), width=15, height=2 )
dstdir = tk.StringVar()
dstdir_button = tk.Button(window, text ="选择加密文件输出目录", command = choose_dstdir )
dstdir_button.pack()
Labeldstdir.pack()
encrypt_button = tk.Button(window, text ="进行加密处理", command = encrypt_button_fun )
encrypt_button.pack()
decrypt_button = tk.Button(window, text ="进行解密处理", command = decrypt_button_fun )
decrypt_button.pack()
out_entry = scrolledtext.ScrolledText(window ,height=4 )
out_entry.pack()
btn_passwd = tk.Button(window, text='重置密码', width=6, command=input_passwd)
btn_passwd.pack(side=tk.LEFT)
window.mainloop()
文档更新时间: 2019-06-16 20:50 作者:月影鹏鹏