MD5加密
from tkinter import *
import hashlib
import time
LOG_LINE_NUM = 0
class mu_gui():
def __init__(self, init_window_name):
self.init_window_name = init_window_name
def set_init_window(self):
self.init_window_name.title='MD5加密工具'
self.init_window_name.geometry('1000x618+20+20')
self.init_window_name['bg'] = 'yellow'
self.init_data_label = Label(self.init_window_name, text='待处理数据')
self.init_data_label.grid(row=0, column=0)
self.result_data_label = Label(self.init_window_name, text='输出结果')
self.result_data_label.grid(row=0, column=12)
self.log_label = Label(self.init_window_name, text='日志')
self.log_label.grid(row=12, column=0)
self.init_data_text = Text(self.init_window_name, width=67, height=35)
self.init_data_text.grid(row=1, column=0, rowspan=10, columnspan=10)
self.result_data_text = Text(self.init_window_name, width=70, height=49)
self.result_data_text.grid(row=1, column=12, rowspan=15, columnspan=10)
self.log_text = Text(self.init_window_name, width=67, height=9)
self.log_text.grid(row=13, column=0, columnspan=11)
self.mod5_button = Button(self.init_window_name, text='转换成MD5', bg='violet',
width=10, command=self.str_trains_to_md5)
self.mod5_button.grid(row=1, column=11)
def str_trains_to_md5(self):
src = self.init_data_text.get(1.0, END).strip().replace('\n', '').encode()
if src:
try:
myMd5 = hashlib.md5()
myMd5.update(src)
myMd5_Digest = myMd5.hexdigest()
self.result_data_text.delete(1.0, END)
self.result_data_text.insert(1.0, myMd5_Digest)
self.print_log_to_text("INFO: 字符串加密成功")
except:
self.result_data_text.delete(1.0, END)
self.result_data_text.insert(1.0, '字符串加密失败-')
else:
self.print_log_to_text("ERROR: 字符串加密失败")
def get_current_time(self):
current_time = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(time.time()))
return current_time
def print_log_to_text(self, logmsg):
global LOG_LINE_NUM
current_time = self.get_current_time()
logmsg_in = str(current_time)+" "+str(logmsg)+"\n"
if LOG_LINE_NUM <= 7:
self.log_text.insert(END, logmsg_in)
LOG_LINE_NUM += 1
else:
self.log_text.delete((1.0, 2.0))
self.log_text.insert(END, logmsg_in)