文件分类tkinter UI小程序,界面点击,后台自动归档到某个文件夹
生活随笔
收集整理的這篇文章主要介紹了
文件分类tkinter UI小程序,界面点击,后台自动归档到某个文件夹
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
import os
import tkinter
import tkinter.messageboxfrom PIL import Image, ImageTkreadPicPath = '6000/Original-delete/'# 創建tkinter應用程序窗口
root = tkinter.Tk()
# 設置窗口的大小和位置
root.geometry('1200x850+40+30')
# 不允許改變窗口的大小
root.resizable(False, False)
# 設置窗口主題
root.title('使用Label顯示圖片')# 獲取當前文件夾中所有圖片文件列表
suffix = ('.jpg', '.bmp', '.png')
pics = [p for p in os.listdir(readPicPath) if p.endswith(suffix)]
# pics.sort(key=lambda item: int(item[:item.index('.')]))# 定義識別正確和錯誤的圖片存放列表
current = 0
correctList = []
errorList = []
deleteList = []def changePic(flag):'''flag參數作為上下圖片的調節 -1代表上一張 1代表下一個'''global currentnew = current + flagif new < 0:tkinter.messagebox.showerror('', '這已經是第一張圖片了')elif new >= len(pics):tkinter.messagebox.showerror('', '這已經是最后一張圖片了')else:# 獲取要切換圖片文件名pic = pics[new]# 創建Image對象并進行縮放im = Image.open(os.path.join(readPicPath, pic))w, h = im.size# 這里假設用來顯示圖片的Label組件尺寸為 400x600if w > 800:h = int(h * 800 / w)w = 800if h > 1200:w = int(w * 1200 / h)h = 1200im = im.resize((w, h))# 創建image對象,并設置Label組件圖片im1 = ImageTk.PhotoImage(im)lbPic['image'] = im1lbPic.image = im1current = newdef deletePic(idx): pic = pics[idx]im = Image.open(os.path.join(readPicPath, pic))im.save(f'delete/{pic}')def correctPic(idx):pic = pics[idx]im = Image.open(os.path.join(readPicPath, pic))im.save(f'correct/{pic}')def errorPic(idx):pic = pics[idx]im = Image.open(os.path.join(readPicPath, pic))im.save(f'error/{pic}')def removePic(idx):pic = pics[idx]file_name = os.path.join(readPicPath, pic)if os.path.exists(file_name):os.remove(file_name)print(f"移除成功: {file_name}")else:print(f"未找到圖片: {file_name}")# 上一張的按鈕
def btnPreClick():changePic(-1)btnPre = tkinter.Button(root, text='上一張', command=btnPreClick)
btnPre.place(x=100, y=20, width=80, height=30)# 下一張按鈕
def btnNextClick():changePic(1)btnNext = tkinter.Button(root, text='下一張', command=btnNextClick)
btnNext.place(x=230, y=20, width=80, height=30)# 刪除按鈕
def btnDeleteClick():global currentdeletePic(current)removePic(current)changePic(1)btnNext = tkinter.Button(root, text='刪除', command=btnDeleteClick)
btnNext.place(x=360, y=20, width=80, height=30)# 識別正確按鈕
def btnCorrectClick():global currentcorrectPic(current)removePic(current)changePic(1)btnNext = tkinter.Button(root, text='識別正確Yes', command=btnCorrectClick)
btnNext.place(x=490, y=20, width=80, height=30)# 識別錯誤按鈕
def btnErrorClick():global currenterrorPic(current)removePic(current)changePic(1)btnNext = tkinter.Button(root, text='識別錯誤NO', command=btnErrorClick)
btnNext.place(x=620, y=20, width=80, height=30)# 用來顯示圖片的Label組件
lbPic = tkinter.Label(root, text=readPicPath, width=800, height=1200)
changePic(0)
lbPic.place(x=10, y=50, width=1200, height=800)# 啟動
root.mainloop()
?
總結
以上是生活随笔為你收集整理的文件分类tkinter UI小程序,界面点击,后台自动归档到某个文件夹的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将所有单个json标注文件合并成一个总的
- 下一篇: 线段检测网格检测(LCNN)的wiref