自己用python写的一款编码工具,包含json格式美化、base64/32编码、url编码解码、16进制编码解码、MD5加密
这里直接把代码贴上了,还有已经把python编译成exe了,有需要可以直接下载附件。
要加什么编码转换的可以留言,可以继续改进。
- import json
- import base64
- import urllib.parse
- import binascii
- import hashlib
- from tkinter import *
- from tkinter import ttk
- from tkinter import scrolledtext
- import tkinter as tk
- win = tk.Tk()
- win.title('编码转换工具 v1.0 By:天眼')
- win.geometry("900x600+300+200")
- ttk.Style().configure(".", font=("仿宋", 15))
- def json1():
- txt = scr1.get('0.0', 'end')
- a = json.loads(txt)#这是以字符串格式转换成json
- b = json.dumps(a,sort_keys=True,indent=4,separators=(',',':'),ensure_ascii=False)
- scr2.insert(END,b)#输出,需要通过插入来输出
- def json2():
- scr1.delete('0.0','end')
- scr2.delete('0.0','end')
- tab = ttk.Notebook(win)
- frame = tk.Frame(tab)
- tb1 = tab.add(frame,text = " json格式转换 ")
- scr1 = scrolledtext.ScrolledText(frame, width=95, height=17,font=(1))
- scr2 = scrolledtext.ScrolledText(frame, width=95, height=17,font=(1))
- scr1.place(x = 0,y = 0)
- scr2.place(x = 0,y = 285)
- button = Button(frame,text="转换",width=10,command = json1)#按钮
- button1 = Button(frame,text="清除",width=10,command = json2)#按钮
- button.place(x = 800,y = 100)
- button1.place(x = 800,y = 390)
- #--------------------------------------------
- def b64():#编码
- txt = scr3.get('0.0', 'end')
- strip = txt.strip('\n')
- e = base64.b64encode(strip.encode('utf-8')).decode('ascii')
- scr4.insert(END,e)
- def b643():#解码
- txt = scr3.get('0.0', 'end')
- strip = txt.strip('\n')
- e = base64.b64decode(strip.encode('utf-8'))
- b = e.decode()
- scr4.insert(END,b)
- def b32():
- txt = scr3.get('0.0', 'end')
- strip = txt.strip('\n')
- e = base64.b32encode(strip.encode('utf-8')).decode('ascii')
- scr4.insert(END,e)
- def b32a():#解码
- txt = scr3.get('0.0', 'end')
- strip = txt.strip('\n')
- e = base64.b32decode(strip.encode('utf-8'))
- b = e.decode()
- scr4.insert(END,b)
- def b642():#清除
- scr3.delete('0.0','end')
- scr4.delete('0.0','end')
- frame1 = tk.Frame(tab)
- tab2 = tab.add(frame1,text = " base64和32编码/解码 ")
- scr3 = scrolledtext.ScrolledText(frame1, width=95, height=17,font=(1))
- scr4 = scrolledtext.ScrolledText(frame1, width=95, height=17,font=(1))
- scr3.place(x = 0,y = 0)
- scr4.place(x = 0,y = 285)
- button2 = Button(frame1,text="ba64编码",width=10, command = b64)#按钮
- button22 = Button(frame1,text="ba64解码",width=10, command = b643)
- button20 = Button(frame1,text="ba32编码",width=10, command = b32)
- button23 = Button(frame1,text="ba32解码",width=10, command = b32a)
- button3 = Button(frame1,text="清除",width=10 , command = b642)#按钮
- button2.place(x = 800,y = 30)
- button22.place(x = 800,y = 80)#x左右,y是上下
- button3.place(x = 800,y = 390)
- button20.place(x = 800,y = 160)#x左右,y是上下
- button23.place(x = 800,y = 210)
- #--------------------------------------------------------------
- def url():
- txt = scr5.get('0.0','end')
- strip = txt.strip('\n')
- a = urllib.parse.quote(strip)
- scr6.insert('0.0',a)
- def url1():
- txt = scr5.get('0.0', 'end')
- strip = txt.strip('\n')
- a = urllib.parse.unquote(strip)
- scr6.insert('0.0',a)
- def url2():#清除
- scr5.delete('0.0','end')
- scr6.delete('0.0','end')
- frame2 = tk.Frame(tab)
- tab3 = tab.add(frame2,text = " URL编码/解码 ")
- scr5 = scrolledtext.ScrolledText(frame2, width=95, height=17,font=(1))
- scr6 = scrolledtext.ScrolledText(frame2, width=95, height=17,font=(1))
- scr5.place(x = 0,y = 0)
- scr6.place(x = 0,y = 285)
- button4 = Button(frame2,text="编码",width=10,command = url)#按钮
- button44 = Button(frame2,text="解码",width=10, command = url1)
- button5 = Button(frame2,text="清除",width=10,command = url2)#按钮
- button4.place(x = 800,y = 50)
- button44.place(x = 800,y = 150)
- button5.place(x = 800,y = 390)
- #------------------------------------------
- def hex():
- txt = scr7.get('0.0','end')
- strip = txt.strip('\n')
- c = strip.encode()
- a =binascii.hexlify(c).decode('ascii')
- scr8.insert('0.0',a)
- def hex1():
- b = scr7.get('0.0','end')
- a = binascii.unhexlify(b.strip('\n')).decode('ascii')
- scr8.insert('0.0',a)
- def hex2():#清除
- scr7.delete('0.0','end')
- scr8.delete('0.0','end')
- frame3 = tk.Frame(tab)
- tab4 = tab.add(frame3,text = " 16进制编码/解码 ")
- scr7 = scrolledtext.ScrolledText(frame3, width=95, height=17,font=(1))
- scr8 = scrolledtext.ScrolledText(frame3, width=95, height=17,font=(1))
- scr7.place(x = 0,y = 0)
- scr8.place(x = 0,y = 285)
- button6 = Button(frame3,text="编码",width=10,command = hex)#按钮
- button66 = Button(frame3,text="解码",width=10,command = hex1)
- button7 = Button(frame3,text="清除",width=10,command = hex2)#按钮
- button6.place(x = 800,y = 50)
- button66.place(x = 800,y = 150)
- button7.place(x = 800,y = 390)
- #-------------------------------------------
- def md5():
- txt = scr9.get('0.0','end')
- b = txt.strip('\n')
- a = hashlib.md5(b.encode(encoding='UTF-8')).hexdigest()
- scr10.insert('0.0',a)
- def md51():#清除
- scr9.delete('0.0','end')
- scr10.delete('0.0','end')
- frame4 = tk.Frame(tab)
- tab5 = tab.add(frame4,text = " MD5加密 ")
- scr9 = scrolledtext.ScrolledText(frame4, width=95, height=17,font=(1))
- scr10 = scrolledtext.ScrolledText(frame4, width=95, height=17,font=(1))
- scr9.place(x = 0,y = 0)
- scr10.place(x = 0,y = 285)
- button8 = Button(frame4,text="加密",width=10,command = md5)#按钮
- button9 = Button(frame4,text="清除",width=10,command = md51)#按钮
- button8.place(x = 800,y = 50)
- button9.place(x = 800,y = 390)
- tab.pack(expand = True, fill = 'both')
- win.mainloop()
在这里还是要推荐下我自己建的Python学习群:553215015,群里都是学Python的,如果你想学或者正在学习Python ,欢迎你加入,大家都是软件开发党,不定期分享干货(只有Python软件开发相关的),包括我自己整理的一份2020最新的Python进阶资料和零基础教学,欢迎进阶中和对Python感兴趣的小伙伴加入!