# coding:utf-8 import tkinter as tk import base64 import tkinter.messagebox as tm def get_encode(): get_var = te1.get("1.0", "end") en_str = base64.b64encode(get_var.encode("gbk")) en_result = en_str.decode("gbk") tt1.delete("1.0", "end") var2.set("加密结果如下:") tt1.insert("insert", en_result) def get_decode(): get_var = bytes(te1.get("1.0", "end"), encoding="gbk") en_str = base64.b64decode(get_var) en_result = en_str.decode("gbk") tt1.delete("1.0", "end") var2.set("加密结果如下:") tt1.insert("insert", en_result)
def menuCommand():
tm.showinfo("", "功能暂未开放")
def add_menu(name):
main_menu.add_command(label=f"{
name}", command=menuCommand)
window = tk.Tk()
width = 1100
height = 650
window_width = int((window.winfo_screenwidth()-width)/2)
window_height = int((window.winfo_screenheight()-height)/2)
window.title("Base64转换工具")
window.geometry(f"{
width}x{
height}+{
window_width}+{
window_height}")
window.resizable(0, 0)
# window.iconbitmap(r"favicon.ico")
lb1 = tk.Label(window, text="欢迎使用Base64转换工具", font=("宋体", 14), width=110, height=2, relief="groove",
anchor="center", bg="#FDF5E6")
lb2 = tk.Label(window, text="请在下面输入要加密或者解密的内容:", font=("宋体", 14), width=110, height=2, relief="groove",
anchor="w")
te1 = tk.Text(window, width=100, height=10, bg="#FDF5E6", font=("宋体", 14, 'bold'))
bt1 = tk.Button(window, text="Base64加密", font=("宋体", 14), width=10, height=1, relief="raised",
command=get_encode, anchor="e")
bt2 = tk.Button(window, text="Base64解密", font=("宋体", 14), width=10, height=1, relief="raised",
command=get_decode, anchor="w")
bt3 = tk.Button(window, text="关闭", font=("宋体", 14), width=10, height=1,
relief="raised", command=window.quit, anchor="w")
var2 = tk.StringVar()
var2.set("")
te2 = tk.Label(window, textvariable=var2, bg="#FDF5E6", font=("宋体", 14), width=110, height=2,
relief="groove", anchor="w")
tt1 = tk.Text(window, width=100, height=10, bg="#FDF5E6", font=("宋体", 14, 'bold'))
lb3 = tk.Label(window, text="杨小朋制作出品。", bg="#FDF5E6", font=("宋体", 14), width=110, height=2,
anchor="center")
lb4 = tk.Label(window, text="联系方式:2969868321@qq.com ", bg="#FDF5E6", font=("宋体", 14), width=110, height=2,
anchor="e")
lb1.grid(row=0, column=0, columnspan=6)
lb2.grid(row=1, column=0, columnspan=6)
te1.grid(row=2, column=0, columnspan=6)
bt1.grid(row=3, column=2, columnspan=1)
bt2.grid(row=3, column=3, columnspan=1)
bt3.grid(row=3, column=4, columnspan=1)
te2.grid(row=4, column=0, columnspan=6)
tt1.grid(row=5, column=0, columnspan=6)
lb3.grid(row=6, column=0, columnspan=6)
lb4.grid(row=7, column=0, columnspan=6)
main_menu = tk.Menu()
add_menu("文件")
add_menu("修改")
add_menu("保存")
add_menu("撤销")
add_menu("关闭")
window.config(menu=main_menu)
window.mainloop()