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á!