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

发布于 2024-12-21 13:37:55 字数 76 浏览 2 评论 0原文

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

The FileDialog in pyqt is an excellent way to get one path for a file from the user, but is there a good way to get a large number of file selections from the user?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仙气飘飘 2024-12-28 13:37:55

使用 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_())

Use QFileDialog.getOpenFileNames to allow the user to select multiple files:

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_())
儭儭莪哋寶赑 2024-12-28 13:37:55

我建议您让用户使用拖放功能直接从他们最喜欢的文件浏览器中添加文件。因为我在 wxpython 中做到了这一点,没有任何问题,并且用户反馈非常好:)

I would suggest you to let the user use drag & drop to add files directly from their favorite file browser. As I did this in wxpython without any trouble and user-feedbacks are pretty good :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文