-
Notifications
You must be signed in to change notification settings - Fork 25
/
tool_correct.py
62 lines (51 loc) · 1.6 KB
/
tool_correct.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import os
import shutil
import tkinter as tk
from tkinter import simpledialog
from PIL import Image, ImageTk
# 获取图片文件列表
image_folder = "captcha_img_ocr/fail"
image_files = [f for f in os.listdir(image_folder) if f.endswith(".jpg")]
path_out = "captcha_img_ocr/correct"
if not os.path.exists(path_out):
os.makedirs(path_out)
# 初始化窗口
root = tk.Tk()
root.title("Image Viewer")
root.geometry("500x300") # 设置窗口初始大小
# 初始化图片索引
current_index = 0
# 显示图片函数
def show_image():
global current_index
file = image_files[current_index]
image_path = os.path.join(image_folder, file)
img = Image.open(image_path)
img = img.resize((80 * 4, 25 * 4), Image.ANTIALIAS)
img_tk = ImageTk.PhotoImage(img)
label.config(image=img_tk)
label.image = img_tk
# 切换图片函数
def next_image(event):
global current_index
file = image_files[current_index]
user_input = entry.get() # 获取输入框内容
new_file = user_input.upper() + "_" + file.split("_")[1]
shutil.move(os.path.join(image_folder, file), os.path.join(path_out, new_file))
entry.delete(0, tk.END) # 清空输入框内容
current_index += 1
if current_index == len(image_files):
print("finish")
exit(0)
else:
show_image()
# 显示第一张图片
label = tk.Label(root)
label.pack()
show_image()
# 创建输入框,等待用户输入并按下回车
entry = tk.Entry(root)
entry.bind("<Return>", next_image)
entry.pack()
# 运行主循环
root.mainloop()