python - PyQt:如何从用户那里获取大量文件名?

标签 python pyqt pyqt4 qfiledialog

pyqt 中的 FileDialog 是从用户那里获取文件的一个路径的好方法,但是有没有一种从用户那里获取大量文件选择的好方法?

最佳答案

使用QFileDialog.getOpenFileNames允许用户选择多个文件:

from PyQt4 import QtGui, QtCore

class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QVBoxLayout(self)
        self.button = QtGui.QPushButton('Select Files', self)
        layout.addWidget(self.button)
        self.button.clicked.connect(self.handleButton)

    def handleButton(self):
        title = self.button.text()
        for path in QtGui.QFileDialog.getOpenFileNames(self, title):
            print path

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.show()
    sys.exit(app.exec_())

关于python - PyQt:如何从用户那里获取大量文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8498475/

相关文章:

python - 预测单个时隙的位置点集

python - 如何使用 PyQt5 QCompleter 进行代码补全

drag-and-drop - 如何拖放到 QTableWidget 中? (PyQT)

python - 如何重启 PyQt5 应用程序

qt - 无法在悬停样式表上获得带有边框的平面 QToolButton

python - 运行并行解析函数 python scrapy

python - Chrome 版本自动安装 Chrome 驱动

python - 安装pyQt4时找不到sip.h

python - 从 Excel 填充 QTableWidget

python - 如何创建 django 子域