如何在wxPython中加载多个图像?

2024-10-02 00:26:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在努力学习如何使用wxFileDialog从一个文件夹中加载多个图片,然后将这些图片添加到一个数组中。代码如下:

def loadImages(self, e):
    wildcard = 'JPEG files (*.jpg)|*.jpg|' +\
               'PNG files (*.png)|*.png|' +\
               'Other files (*.*)|*.*'
    dlg = wx.FileDialog(self, "Choose images", 
                        wildcard=wildcard, style=wx.FD_OPEN | wx.FD_MULTIPLE)
    if dlg.ShowModal() == wx.ID_OK:
        self.imageName = dlg.GetFilename()
        self.directory = dlg.GetDirectory()
        self.image = self.directory + '/' + self.imageName
    for dlg in dlg.GetPaths():
        image = Image.open(dlg)
        self.imagesA = np.append(self.imagesA, image)
dlg.Destroy()

任何帮助都将不胜感激。谢谢!你知道吗


Tags: imageself文件夹png图片filesdirectorywildcard

热门问题