python 写的编码转换工具

自己用python写了一个转换小工具,有json格式转换,base64编码转换、url编码转换,16进制编码转换、md5加密,然后用tkinter模块搭建了个可视化窗口 需要源码的可以自己查看,不需要源码的提供编译后的工具

编译后的工具也上传了可以下载https://download.csdn.net/download/qq_39650046/13129121
由于通过pyinstaller模块编译导致杀毒软件会报毒,添加信任就行

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')#16进制转回来不能存在换行符
	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()
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值