1
1
# -*- coding: utf-8 -*-
2
2
3
- import tkinter as tk
3
+ import tkinter as ttk
4
4
import tkinter .messagebox
5
5
from tkinter .filedialog import askopenfilenames
6
6
from base64 import b64encode , b64decode , b32encode , b32decode
9
9
from hashlib import md5
10
10
from pathlib import Path
11
11
12
- window = tk .Tk ()
12
+ window = ttk .Tk ()
13
13
window .title ('DEcoder' )
14
14
window .geometry ('800x650' )
15
15
16
16
# Base64/32编码解码
17
17
# 窗体名称
18
- b64Text = tk .Label (window , text = 'Base64/32编码解码:' , font = ('微软雅黑' , 16 ))
18
+ b64Text = ttk .Label (window , text = 'Base64/32编码解码:' , font = ('微软雅黑' , 16 ))
19
19
b64Text .place (x = 10 , y = 10 , anchor = 'nw' )
20
20
# 左侧输入输出框
21
- b64_input = tk .Text (window , height = 8 , width = 40 )
21
+ b64_input = ttk .Text (window , height = 8 , width = 40 )
22
22
b64_input .place (x = 10 , y = 40 , anchor = 'nw' )
23
23
# 右侧输入输出框
24
- b64_output = tk .Text (window , height = 8 , width = 40 )
24
+ b64_output = ttk .Text (window , height = 8 , width = 40 )
25
25
b64_output .place (x = 500 , y = 40 , anchor = 'nw' )
26
26
27
27
@@ -68,40 +68,46 @@ def base_select_encode():
68
68
69
69
def base_select_decode ():
70
70
if var_base_num .get () == "base32" :
71
- return b32_decode ()
71
+ try :
72
+ return b32_decode ()
73
+ except :
74
+ tkinter .messagebox .showerror (title = '错误' , message = '解码错误,请检查输入' )
72
75
if var_base_num .get () == "base64" :
73
- return b64_decode ()
76
+ try :
77
+ return b64_decode ()
78
+ except :
79
+ tkinter .messagebox .showerror (title = '错误' , message = '解码错误,请检查输入' )
74
80
75
81
76
82
# 选择按钮
77
- var_base_num = tk .StringVar (None , 'base64' ) # 设置默认值为base64
78
- base_num1 = tk .Radiobutton (window , text = 'base32' , variable = var_base_num , value = 'base32' )
83
+ var_base_num = ttk .StringVar (None , 'base64' ) # 设置默认值为base64
84
+ base_num1 = ttk .Radiobutton (window , text = 'base32' , variable = var_base_num , value = 'base32' )
79
85
base_num1 .place (x = 310 , y = 65 , anchor = 'nw' )
80
- base_num2 = tk .Radiobutton (window , text = 'base64' , variable = var_base_num , value = 'base64' )
86
+ base_num2 = ttk .Radiobutton (window , text = 'base64' , variable = var_base_num , value = 'base64' )
81
87
base_num2 .place (x = 410 , y = 65 , anchor = 'nw' )
82
88
83
89
# 选择按钮
84
- var_base_type = tk .StringVar (None , 'utf-8' ) # 设置默认值为utf-8
85
- base_type1 = tk .Radiobutton (window , text = 'gbk' , variable = var_base_type , value = 'gbk' )
90
+ var_base_type = ttk .StringVar (None , 'utf-8' ) # 设置默认值为utf-8
91
+ base_type1 = ttk .Radiobutton (window , text = 'gbk' , variable = var_base_type , value = 'gbk' )
86
92
base_type1 .place (x = 310 , y = 40 , anchor = 'nw' )
87
- base_type2 = tk .Radiobutton (window , text = 'utf-8' , variable = var_base_type , value = 'utf-8' )
93
+ base_type2 = ttk .Radiobutton (window , text = 'utf-8' , variable = var_base_type , value = 'utf-8' )
88
94
base_type2 .place (x = 410 , y = 40 , anchor = 'nw' )
89
95
90
96
# 编码解码按钮
91
- b1 = tk .Button (window , text = '编码 -->' , width = 10 , height = 1 , command = base_select_encode )
92
- b2 = tk .Button (window , text = '<-- 解码' , width = 10 , height = 1 , command = base_select_decode )
97
+ b1 = ttk .Button (window , text = '编码 -->' , width = 10 , height = 1 , command = base_select_encode )
98
+ b2 = ttk .Button (window , text = '<-- 解码' , width = 10 , height = 1 , command = base_select_decode )
93
99
b1 .place (x = 335 , y = 95 , anchor = 'nw' )
94
100
b2 .place (x = 335 , y = 120 , anchor = 'nw' )
95
101
96
102
# URL编码解码
97
103
# 窗体名称
98
- urlText = tk .Label (window , text = 'URL编码解码:' , font = ('微软雅黑' , 16 ))
104
+ urlText = ttk .Label (window , text = 'URL编码解码:' , font = ('微软雅黑' , 16 ))
99
105
urlText .place (x = 10 , y = 160 , anchor = 'nw' )
100
106
# 左侧输入输出框
101
- url_input = tk .Text (window , height = 6 , width = 40 )
107
+ url_input = ttk .Text (window , height = 6 , width = 40 )
102
108
url_input .place (x = 10 , y = 190 , anchor = 'nw' )
103
109
# 右侧输入输出框
104
- url_output = tk .Text (window , height = 6 , width = 40 )
110
+ url_output = ttk .Text (window , height = 6 , width = 40 )
105
111
url_output .place (x = 500 , y = 190 , anchor = 'nw' )
106
112
107
113
@@ -121,7 +127,10 @@ def url_key_encode():
121
127
122
128
def url_decode ():
123
129
result = url_output .get ("0.0" , "end" ) # 从0行0列获取输入值直到结束
124
- result = unquote (result .strip ())
130
+ try :
131
+ result = unquote (result .strip ())
132
+ except :
133
+ tkinter .messagebox .showerror (title = '错误' , message = '解码错误,请检查输入' )
125
134
url_input .delete ("0.0" , "end" ) # 每次输出结果前先清空文本框内的内容
126
135
url_input .insert ('end' , result )
127
136
@@ -134,27 +143,27 @@ def url_select_encode():
134
143
135
144
136
145
# 选择按钮
137
- var_url_type = tk .StringVar (None , 'key' ) # 设置默认值为全编码
138
- url_type1 = tk .Radiobutton (window , text = '全编码' , variable = var_url_type , value = 'all' )
146
+ var_url_type = ttk .StringVar (None , 'key' ) # 设置默认值为全编码
147
+ url_type1 = ttk .Radiobutton (window , text = '全编码' , variable = var_url_type , value = 'all' )
139
148
url_type1 .place (x = 310 , y = 190 , anchor = 'nw' )
140
- url_type2 = tk .Radiobutton (window , text = '关键词编码' , variable = var_url_type , value = 'key' )
149
+ url_type2 = ttk .Radiobutton (window , text = '关键词编码' , variable = var_url_type , value = 'key' )
141
150
url_type2 .place (x = 400 , y = 190 , anchor = 'nw' )
142
151
143
152
# 编码解码按钮
144
- c1 = tk .Button (window , text = '编码 -->' , width = 10 , height = 1 , command = url_select_encode )
145
- c2 = tk .Button (window , text = '< --解码' , width = 10 , height = 1 , command = url_decode )
153
+ c1 = ttk .Button (window , text = '编码 -->' , width = 10 , height = 1 , command = url_select_encode )
154
+ c2 = ttk .Button (window , text = '< --解码' , width = 10 , height = 1 , command = url_decode )
146
155
c1 .place (x = 335 , y = 215 , anchor = 'nw' )
147
156
c2 .place (x = 335 , y = 240 , anchor = 'nw' )
148
157
149
158
# 字符串与HEX互转
150
159
# 窗体名称
151
- unicodeText = tk .Label (window , text = '字符串与hex互转:' , font = ('微软雅黑' , 16 ))
160
+ unicodeText = ttk .Label (window , text = '字符串与hex互转:' , font = ('微软雅黑' , 16 ))
152
161
unicodeText .place (x = 10 , y = 280 , anchor = 'nw' )
153
162
# 左侧输入输出框
154
- unicode_input = tk .Text (window , height = 3.5 , width = 40 )
163
+ unicode_input = ttk .Text (window , height = 3.5 , width = 40 )
155
164
unicode_input .place (x = 10 , y = 310 , anchor = 'nw' )
156
165
# 右侧输入输出框
157
- unicode_output = tk .Text (window , height = 3.5 , width = 40 )
166
+ unicode_output = ttk .Text (window , height = 3.5 , width = 40 )
158
167
unicode_output .place (x = 500 , y = 310 , anchor = 'nw' )
159
168
160
169
@@ -174,20 +183,20 @@ def unicoce_decode():
174
183
unicode_input .insert ('end' , result )
175
184
176
185
177
- d1 = tk .Button (window , text = 'str to hex -->' , width = 10 , height = 0 , command = unicode_encode )
178
- d2 = tk .Button (window , text = '<-- hex to str' , width = 10 , height = 0 , command = unicoce_decode )
186
+ d1 = ttk .Button (window , text = 'str to hex -->' , width = 10 , height = 0 , command = unicode_encode )
187
+ d2 = ttk .Button (window , text = '<-- hex to str' , width = 10 , height = 0 , command = unicoce_decode )
179
188
d1 .place (x = 335 , y = 310 , anchor = 'nw' )
180
189
d2 .place (x = 335 , y = 340 , anchor = 'nw' )
181
190
182
191
# ASCII与字符串互转
183
192
# 窗体名称
184
- ascText = tk .Label (window , text = '字符串与ASCII互转:' , font = ('微软雅黑' , 16 ))
193
+ ascText = ttk .Label (window , text = '字符串与ASCII互转:' , font = ('微软雅黑' , 16 ))
185
194
ascText .place (x = 10 , y = 380 , anchor = 'nw' )
186
195
# 左侧输入输出框
187
- asc_input = tk .Text (window , height = 3.5 , width = 40 )
196
+ asc_input = ttk .Text (window , height = 3.5 , width = 40 )
188
197
asc_input .place (x = 10 , y = 410 , anchor = 'nw' )
189
198
# 右侧输入输出框
190
- asc_output = tk .Text (window , height = 3.5 , width = 40 )
199
+ asc_output = ttk .Text (window , height = 3.5 , width = 40 )
191
200
asc_output .place (x = 500 , y = 410 , anchor = 'nw' )
192
201
193
202
@@ -220,18 +229,18 @@ def asc_decode(): # 目前仅支持连续的中文和英文ascii转字符串
220
229
asc_input .insert ('end' , result_out )
221
230
222
231
223
- e1 = tk .Button (window , text = 'str to ASCII -->' , width = 10 , height = 0 , command = asc_encode )
224
- e2 = tk .Button (window , text = '<-- ASCII to str' , width = 10 , height = 0 , command = asc_decode )
232
+ e1 = ttk .Button (window , text = 'str to ASCII -->' , width = 10 , height = 0 , command = asc_encode )
233
+ e2 = ttk .Button (window , text = '<-- ASCII to str' , width = 10 , height = 0 , command = asc_decode )
225
234
e1 .place (x = 335 , y = 410 , anchor = 'nw' )
226
235
e2 .place (x = 335 , y = 440 , anchor = 'nw' )
227
236
228
237
229
238
# md5加密
230
239
# 窗体名称
231
- md5Text = tk .Label (window , text = 'md5 hash 计算:' , font = ('微软雅黑' , 16 ))
240
+ md5Text = ttk .Label (window , text = 'md5 hash 计算:' , font = ('微软雅黑' , 16 ))
232
241
md5Text .place (x = 10 , y = 480 , anchor = 'nw' )
233
242
# 左侧输入输出框
234
- md5_input = tk .Text (window , height = 2 , width = 40 )
243
+ md5_input = ttk .Text (window , height = 2 , width = 40 )
235
244
md5_input .place (x = 10 , y = 510 , anchor = 'nw' )
236
245
237
246
@@ -248,21 +257,21 @@ def select_file():
248
257
249
258
250
259
# 文件选择框
251
- md5_text = tk .Text (window , height = 4 , width = 40 )
260
+ md5_text = ttk .Text (window , height = 4 , width = 40 )
252
261
md5_text .place (x = 10 , y = 560 , anchor = 'nw' )
253
262
md5_text .insert ('end' , '可以选择单个文件或多个文件!' )
254
263
# 文件选择按钮
255
- md5_file_buttom = tk .Button (window , text = '选择文件' , width = 5 , height = 0 , command = select_file )
264
+ md5_file_buttom = ttk .Button (window , text = '选择文件' , width = 5 , height = 0 , command = select_file )
256
265
md5_file_buttom .place (x = 300 , y = 600 , anchor = 'nw' )
257
266
# 右侧输出框
258
- md5_output = tk .Text (window , height = 6 , width = 40 )
267
+ md5_output = ttk .Text (window , height = 6 , width = 40 )
259
268
md5_output .place (x = 500 , y = 530 , anchor = 'nw' )
260
269
261
270
# 选择按钮
262
- var_md5_type = tk .StringVar (None , '32' ) # 设置默认值为全编码
263
- md5_type1 = tk .Radiobutton (window , text = 'md5(16)' , variable = var_md5_type , value = '16' )
271
+ var_md5_type = ttk .StringVar (None , '32' ) # 设置默认值为全编码
272
+ md5_type1 = ttk .Radiobutton (window , text = 'md5(16)' , variable = var_md5_type , value = '16' )
264
273
md5_type1 .place (x = 310 , y = 510 , anchor = 'nw' )
265
- md5_type2 = tk .Radiobutton (window , text = 'md5(32)' , variable = var_md5_type , value = '32' )
274
+ md5_type2 = ttk .Radiobutton (window , text = 'md5(32)' , variable = var_md5_type , value = '32' )
266
275
md5_type2 .place (x = 400 , y = 510 , anchor = 'nw' )
267
276
268
277
@@ -323,9 +332,9 @@ def md5_select_file():
323
332
return md5_file_32 ()
324
333
325
334
326
- f1 = tk .Button (window , text = '文本hash -->' , width = 10 , height = 0 , command = md5_select )
335
+ f1 = ttk .Button (window , text = '文本hash -->' , width = 10 , height = 0 , command = md5_select )
327
336
f1 .place (x = 335 , y = 540 , anchor = 'nw' )
328
- f2 = tk .Button (window , text = '文件hash -->' , width = 10 , height = 0 , command = md5_select_file )
337
+ f2 = ttk .Button (window , text = '文件hash -->' , width = 10 , height = 0 , command = md5_select_file )
329
338
f2 .place (x = 335 , y = 570 , anchor = 'nw' )
330
339
331
340
# 主窗口循环显示
0 commit comments