# -*- coding: utf-8 -*- import tkinter as tk from tkinter import filedialog as tkFileDialog import subprocess import io def start(): window = tk.Tk() # 创建窗口对象的背景色 window.title(u'解码用户的密码') # 设置窗口的标题 window.geometry('400x250') # 设置窗口的大小 title = tk.Label(window, text=u'解码机', font=(u'微软雅黑', 12), width=40, height=3) title.place(x=0,y=0,anchor='nw') # 输入密码 pwd = tk.Label(window,text=u'输入密码:',font=(u'微软雅黑',12),width=20,height=2) pwd.place(x=0,y=50,anchor='nw') path_var1 = tk.StringVar() #输入路径 entry1 = tk.Entry(window, textvariable=path_var1) entry1.place(x=170, y=65, anchor='nw') svpath = tk.Label(window,text=u'保存路径:',font=(u'微软雅黑',12),width=20,height=2) svpath.place(x=0,y=100,anchor='nw') path_var2 = tk.StringVar() #输入路径 5 entry2 = tk.Entry(window, textvariable=path_var2) entry2.place(x=170, y=110, anchor='nw') svdate = tk.Label(window, text=u'有效日期至:\n(格式:20240101)', font=(u'微软雅黑', 12), width=20, height=2) svdate.place(x=0, y=150, anchor='nw') date_var2 = tk.StringVar() # 输入路径 5 entry3 = tk.Entry(window, textvariable=date_var2) entry3.place(x=170, y=155, anchor='nw') def choose1(): file_dir = tkFileDialog.askdirectory() path_var2.set(file_dir) def exchangewdinpy(date,path,wd,mac): # 替换文本 source_file_path = 'passwordtxt_e.py' output_file_path = path + '\\' + wd + '.py' with io.open(source_file_path, 'r', encoding='utf-8') as source_file, io.open(output_file_path, 'w', encoding='utf-8') as output_file: line_number = 1 for line in source_file: if line_number == 182: # 当达到第182行时,写入新的内容 strmac = ' mac=\'' + mac + '\'\n' output_file.write(strmac) elif line_number == 184: strdate = ' date = \''+ date + '\'\n' output_file.write(strdate) else: # 否则,写入原内容 output_file.write(line) line_number += 1 # output_file_path = output_file_path.encode('utf-8') # path = path.encode('utf-8') subprocess.call([ 'pyinstaller', '-F', output_file_path,# 这里替换为你的Python脚本文件名 '--distpath', path ]) def main(): password = entry1.get() path = entry2.get() date = entry3.get() macNumber1= {'a':10,'b':11,'c':12,'d':13,'e':14,'f':15} macNumber2 = {10:'a',11:'b',12:'c',13:'d',14:'e',15:'f',-1:'f',-2:'e',-3:'d'} first = password[0:6] last = password[6:] newpassword = last + first strlist = [] #存放转换后的字符串 for n in newpassword: try: n1 = macNumber1[n] except: n1 = n n2 = int(n1) - 3 if n2 >= 10: n2 = macNumber2[n2] elif n2 < 0 : n2 = macNumber2[n2] strlist.append(str(n2)) mac = ''.join(strlist) exchangewdinpy(date,path, password, mac) def tuichu(): window.destroy() tk.Button(window, text='选择', command=choose1).place(x=320, y=105, anchor='nw') tk.Button(window,text=u'生成',command=main).place(x=120,y=200,anchor='nw') tk.Button(window,text=u'关闭',command=tuichu).place(x=230,y=200,anchor='nw') window.mainloop() if __name__ == '__main__': start() # start("0")