Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何使用KFileDialog选择多个目录?_Python_Linux_Qt_Kde_Pykde - Fatal编程技术网

Python 如何使用KFileDialog选择多个目录?

Python 如何使用KFileDialog选择多个目录?,python,linux,qt,kde,pykde,Python,Linux,Qt,Kde,Pykde,使用PyKDE4.kio选择多个文件,我可以使用KFileDialog.getOpenFileNames(而不是KFileDialog.getOpenFileName)。如果要选择多个目录,我可以做什么?只有KFileDialog.getExistingDirectory 使用KFileDialog.getOpenFileNames(过滤器='inode/directory')并选择多个文件夹显示错误: 已选择多个文件夹,此对话框不接受文件夹,因此无法决定要输入哪个文件夹。请仅选择一个文件夹来列

使用
PyKDE4.kio
选择多个文件,我可以使用
KFileDialog.getOpenFileNames
(而不是
KFileDialog.getOpenFileName
)。如果要选择多个目录,我可以做什么?只有
KFileDialog.getExistingDirectory

使用
KFileDialog.getOpenFileNames(过滤器='inode/directory')
并选择多个文件夹显示错误:

已选择多个文件夹,此对话框不接受文件夹,因此无法决定要输入哪个文件夹。请仅选择一个文件夹来列出它

我从中找到了一个解决方案,并将其转换为python

import sys
from PyQt5.QtWidgets import (QFileDialog, QAbstractItemView, QListView,
                             QTreeView, QApplication, QDialog)

class getExistingDirectories(QFileDialog):
    def __init__(self, *args):
        super(getExistingDirectories, self).__init__(*args)
        self.setOption(self.DontUseNativeDialog, True)
        self.setFileMode(self.Directory)
        self.setOption(self.ShowDirsOnly, True)
        self.findChildren(QListView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.findChildren(QTreeView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)

qapp = QApplication(sys.argv)
dlg = getExistingDirectories()
if dlg.exec_() == QDialog.Accepted:
    print(dlg.selectedFiles())
我从中找到了一个解决方案,并将其转换为python

import sys
from PyQt5.QtWidgets import (QFileDialog, QAbstractItemView, QListView,
                             QTreeView, QApplication, QDialog)

class getExistingDirectories(QFileDialog):
    def __init__(self, *args):
        super(getExistingDirectories, self).__init__(*args)
        self.setOption(self.DontUseNativeDialog, True)
        self.setFileMode(self.Directory)
        self.setOption(self.ShowDirsOnly, True)
        self.findChildren(QListView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.findChildren(QTreeView)[0].setSelectionMode(QAbstractItemView.ExtendedSelection)

qapp = QApplication(sys.argv)
dlg = getExistingDirectories()
if dlg.exec_() == QDialog.Accepted:
    print(dlg.selectedFiles())

你能添加剩下的代码来弹出文件对话框窗口吗?@guillome et voilá!你能添加剩下的代码来弹出文件对话框窗口吗?@guillome et voilá!