效果圖:
剛啟動的狀態

輸入文本、觸發加密按鈕后支持復制

超過十條不全量顯示

代碼
import hashlib
import tkinter as tk
#視窗控制
windowss=tk.Tk()
windowss.title('Python_md5')#視窗title,并非第一行
windowss.geometry('820x550')
windowss.resizable(width=True, height=True)#寬度可變,高度可變
#label組件-文本標簽
label1=tk.Label(windowss,text="請輸入文本").grid(row=0, column=0)#生成label
label2=tk.Label(windowss,text="MD5:").grid(row=3, column=0)#生成結果固定label
label3=tk.Label(windowss,text="SHA256:").grid(row=4, column=0)#生成結果固定label
#entry組件-文本輸入框
E12=tk.Text(windowss,width=80,bd=2.5,height=10,relief="sunken")
E12.grid(row=0,column=1)#輸入正則運算式入口
#進入決議模式
judge_text1 = tk.StringVar()
judge_text1.set("暫未輸入")
judge_text2 = tk.StringVar()
judge_text2.set("")
def copy(text2):
windowss.clipboard_clear() # 清除剪貼板內容
windowss.clipboard_append(text2)
def judge():
text1 = E12.get('0.0','end')#'0.0','end'全量讀取
to_one_line = ' '.join(text1.split())#轉化為串列1
test_list = to_one_line.split(' ')#轉化為串列2
m1=""
m2=""
for texts in test_list:
matcher_md5_new= hashlib.md5(texts.encode('utf8'))#md5轉化
matcher_md5 = str(matcher_md5_new.hexdigest())#獲取md5
m1=m1+"\n"+matcher_md5#分行
matcher_sha256_new = hashlib.sha3_256(texts.encode('utf8'))#轉化為sha256
matcher_sha256 = str(matcher_sha256_new.hexdigest())
m2 = m2 + "\n" + matcher_sha256
if len(test_list)>10:#大于十條資料時,不完全顯示
T3 = tk.Label(windowss,text="").grid(row=5, column=1)
T4 = tk.Label(windowss,text="tips:最大顯示10條決議文本,可全量復制!").grid(row=6, column=1)
judge_text1.set(m1)
judge_text2.set(m2)
#生成復制按鈕,用了lambda可以排除按鈕之間干擾
B2 = tk.Button(windowss, text="復制md5", width=10, height=2, command=lambda:copy(str(m1))).grid(row=1, column=0)
B3 = tk.Button(windowss, text="復制sha256", width=10, height=2, command=lambda:copy(str(m2))).grid(row=1, column=2)
#設定加密按鈕,command表示觸發條件
B1=tk.Button(windowss,text="哈希加密",width=10,height=2,command=judge).grid(row=1,column=1)
#輸出結果
T1 = tk.Label(windowss, width=70, height=10,bd=0,textvariable=judge_text1).grid(row=3, column=1) # 生成結果 md5
T2 = tk.Label(windowss, width=70,height=10, bd=0,textvariable=judge_text2).grid(row=4, column=1) # 生成結果 sha256
windowss.mainloop()#生成前端視窗
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/20091.html
標籤:其他
