如何使用 PyQt5 在 list/array 中添加多个图像的 filename/directory

How can i add the filename/directory of several images in a list/array with PyQt5

我使用 PyQt5 和 QtDesigner 创建一个 GUI,我可以在其中 select 来自文件夹的不同照片。我希望将照片的名称存储在列表中。

例如:

[0]: Image_Nike_AirMax_Size/9.0
[1]: Image_Adidas_Continental_Size/8.5, and so on.

然后我想select每张照片的信息,比如"Size",单独保存在一个变量里

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QDialog
from PyQt5.QtGui import QIcon
from PyQt5.uic import loadUi

class Fenster(QDialog):
    def __init__(self):
        super(Fenster, self).__init__()
        loadUi('Projekt.ui', self)
        #self.b1.clicked.connect(self.gedrueckt)
        self.pushButton_2.clicked.connect(self.button)

    def button(self):
        self.open_dialog_box()

    def open_dialog_box(self):
        filename = QFileDialog.getOpenFileNames(self, 'Select Multi File', 'default', 'All Files (*)'))

        for name in filename:
            idx = name.find("/")
            print(name[idx+1:])


app = QApplication(sys.argv)
w = Fenster()
w.show()
sys.exit(app.exec_())

在我的代码中,您看到了目标的近似值,但它并没有完全实现。

下面的代码将文件存储到一个列表中,将每个文件的大小存储到另一个列表中,最后将两者合并。

import os
from pathlib import Path

    def open_dialog_box(self):
        """Open files and populate lists."""
        full_path, _ = QFileDialog.getOpenFileNames(self, "Select Multi File", os.getcwd())

        # Store files in list
        self.file_list = []
        [self.file_list.append(path) for path in full_path]

        [print(f) for f in self.file_list]

        # Store size of each file in KB
        self.file_size = []
        for f in self.file_list:
            self.file_size.append(Path(f).stat().st_size)

        [print(f) for f in self.file_size]

        # Combine lists
        self.complete = zip(self.file_list, self.file_size)

        [print(c) for c in self.complete]