import
tkinter as tk
from
tkinter
import
ttk, filedialog, messagebox
import
fitz
from
PIL
import
Image
import
io
import
img2pdf
import
threading
import
os
def
set_style():
style
=
ttk.Style()
style.configure(
"TButton"
,
padding
=
8
,
font
=
(
"Segoe UI"
,
9
),
foreground
=
"black"
,
background
=
"#1976D2"
,
relief
=
"flat"
,
borderwidth
=
2
)
style.
map
(
"TButton"
,
background
=
[(
"active"
,
"#1565C0"
), (
"pressed"
,
"#0D47A1"
)],
foreground
=
[(
"disabled"
,
"#888888"
)])
style.configure(
"TEntry"
,
padding
=
10
,
font
=
(
"Segoe UI"
,
9
),
fieldbackground
=
"#F5F5F5"
,
bordercolor
=
"#BDBDBD"
,
relief
=
"solid"
)
style.
map
(
"TEntry"
,
fieldbackground
=
[(
"focus"
,
"#E3F2FD"
)])
style.configure(
"TLabel"
,
font
=
(
"Segoe UI"
,
9
),
background
=
"#FFFFFF"
,
padding
=
5
)
style.configure(
"TLabelframe"
,
font
=
(
"Segoe UI"
,
9
,
"bold"
),
borderwidth
=
2
,
relief
=
"groove"
)
style.configure(
"TLabelframe.Label"
,
font
=
(
"Segoe UI"
,
9
))
def
select_input_file():
file_path
=
filedialog.askopenfilename(
title
=
"选择PDF文件"
,
filetypes
=
[(
"PDF文件"
,
"*.pdf"
), (
"所有文件"
,
"*.*"
)]
)
if
file_path:
input_file_entry.delete(
0
, tk.END)
input_file_entry.insert(
0
, file_path)
root
=
tk.Tk()
root.title(
"扫描文件压缩工具"
)
root.geometry(
"560x480"
)
root.configure(bg
=
"#FFFFFF"
)
root.minsize(
560
,
480
)
set_style()
main_frame
=
ttk.Frame(root, padding
=
24
)
main_frame.grid(row
=
0
, column
=
0
, sticky
=
'nsew'
)
input_frame
=
ttk.LabelFrame(main_frame, text
=
" PDF文件 "
, padding
=
12
)
input_frame.grid(row
=
0
, column
=
0
, columnspan
=
3
, sticky
=
'ew'
, pady
=
8
)
ttk.Label(input_frame, text
=
"文件路径:"
).grid(row
=
0
, column
=
0
, sticky
=
'w'
)
input_file_entry
=
ttk.Entry(input_frame, width
=
40
)
input_file_entry.grid(row
=
0
, column
=
1
, padx
=
8
, sticky
=
'ew'
)
ttk.Button(input_frame, text
=
"选 择"
, command
=
select_input_file).grid(row
=
0
, column
=
2
, padx
=
8
)
main_frame.columnconfigure(
1
, weight
=
1
)
root.columnconfigure(
0
, weight
=
1
)
root.rowconfigure(
0
, weight
=
1
)
root.mainloop()