python实战系列03-URL的编码与解码

亓翎_Re-TikaRa Lv4

  被QQ最近那个点击转发的小东西弄感兴趣了,看是MD语法,重点是URL的编码和解码,所以就写了个简单的例子。


代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import tkinter as tk
from urllib.parse import quote, unquote

def encode_text():
input_text = entry.get()
encoded_text = quote(input_text)
result_label.config(text=encoded_text)

def decode_text():
input_text = entry.get()
try:
decoded_text = unquote(input_text)
result_label.config(text=decoded_text)
except Exception as e:
result_label.config(text="请输入正确的URL编码内容")

def copy_text():
root.clipboard_clear()
root.clipboard_append(result_label.cget("text"))

root = tk.Tk()
root.title("URL编码器")
root.configure(bg="#EEE0E5")

entry = tk.Entry(root, width=50, bg="#FFE4C4")
entry.pack(pady=10)

buttons_frame = tk.Frame(root)
buttons_frame.pack(side="right", padx=10)

encode_button = tk.Button(buttons_frame, text="编码", command=encode_text)
encode_button.pack(pady=5)

decode_button = tk.Button(buttons_frame, text="解码", command=decode_text)
decode_button.pack(pady=5)

copy_button = tk.Button(buttons_frame, text="复制", command=copy_text)
copy_button.pack(pady=5)

result_label = tk.Label(root, text="", bg="#B0E0E6")
result_label.pack(pady=10)

root.mainloop()

下载

Github:https://github.com/NIGHT2000/URL-Encoder-decoder
QQ群:813686446

  • 标题: python实战系列03-URL的编码与解码
  • 作者: 亓翎_Re-TikaRa
  • 创建于 : 2024-05-22 23:41:15
  • 更新于 : 2024-11-20 20:35:15
  • 链接: https://re-tikara.fun/posts/cbf0ad6c/
  • 版权声明: 本文章采用 CC BY-NC-SA 4.0 进行许可。
目录
python实战系列03-URL的编码与解码