使用 Python创建照片文件复制和压缩工具

在这篇博客中,我们将探索如何使用 wxPython 创建一个 GUI 工具,用于选择文件夹中的照片文件、显示预览、选择并复制文件到指定目录,以及将选中的照片压缩到一个 ZIP 文件中。这个工具不仅功能强大,而且提供了用户友好的界面。
C:\pythoncode\new\photofilecopyandzip.py

全部代码

import wx
import os
from datetime import datetime
import shutil
import zipfile

class MyFrame(wx.Frame):
    def __init__(self, *args, **kwargs):
        super(MyFrame, self).__init__(*args, **kwargs)
        
        self.panel = wx.Panel(self)
        self.vbox = wx.BoxSizer(wx.VERTICAL)
        
        self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        self.openBtn = wx.Button(self.panel, label='Open Folder')
        self.selectAllBtn = wx.Button(self.panel, label='Select All')
        self.deselectAllBtn = wx.Button(self.panel, label='Deselect All')
        self.copyBtn = wx.Button(self.panel, label='Copy')
        self.compressBtn = wx.Button(self.panel, label='Compress')
        self.hbox1.Add(self.openBtn)
        self.hbox1.Add(self.selectAllBtn)
        self.hbox1.Add(self.deselectAllBtn)
        self.hbox1.Add(self.copyBtn)
        self.hbox1.Add(self.compressBtn)
        
        self.splitter = wx.SplitterWindow(self.panel)
        
        self.listView = wx.ListCtrl(self.splitter, style=wx.LC_REPORT | wx.BORDER_SUNKEN)
        self.listView.InsertColumn(0, 'Image Files')
        self.listView.InsertColumn(1, 'Size')
        self.listView.InsertColumn(2, 'Dimensions')
        self.listView.InsertColumn(3, 'Date')
        
        self.imagePreview = wx.StaticBitmap(self.splitter)
        
        self.splitter.SplitVertically(self.listView, self.imagePreview)
        self.splitter.SetSashGravity(0.5)
        
        self.vbox.Add(self.hbox1, 0, wx.EXPAND | wx.ALL, 5)
        self.vbox.Add(self.splitter, 1, wx.EXPAND)
        
        self.panel.SetSizer(self.vbox)
        
        self.Bind(wx.EVT_BUTTON, self.on_open_folder, self.openBtn)
        self.Bind(wx.EVT_BUTTON, self.on_select_all, self.selectAllBtn)
        self.Bind(wx.EVT_BUTTON, self.on_deselect_all, self.deselectAllBtn)
        self.Bind(wx.EVT_BUTTON, self.on_copy_photos, self.copyBtn)
        self.Bind(wx.EVT_BUTTON, self.on_compress_photos, self.compressBtn)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.on_item_selected, self.listView)
        
        self.image_paths = {
   
   }
        self.selected_images = []
    
    def on_open_folder(self, event):
        with wx.DirDialog(self, "Choose a directory") as dlg:
            if dlg.ShowModal() == wx.ID_OK:
                folder_path = dlg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值