我有一个名为PDFviewer的python类,在运行程序时,系统会显示一个窗口,处理按钮 (open folder) 将打开一个文件对话框,允许用户选择一个目录并在其中显示文件 .
问题是当我尝试单击按钮时系统崩溃并显示以下错误:
文件“C:\ Users \ test \ Documents \ Python_Projects \ final_project \ myPDFviewer.py”,第36行,在sys.exit(app.exec_())文件“C:\ Users \ test \ Documents \ Python_Projects \ final_project \ myPDFviewer.py“,第24行,在setExistingDirectory options = options中)builtins.TypeError:getExistingDirectory(parent:QWidget = None,caption:str ='',directory:str ='',options:Union [QFileDialog.Options,QFileDialog . 选项] = QFileDialog.ShowDirsOnly):参数1有意外类型'bool'
代码:
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import (QApplication, QCheckBox, QColorDialog, QDialog,
QErrorMessage, QFileDialog, QFontDialog, QFrame, QGridLayout,
QInputDialog, QLabel, QLineEdit, QMessageBox, QPushButton)
from PyQt5.QtCore import QDir, Qt
import pdfviewer
class pdfViewer(pdfviewer.Ui_PdfPreviewWindow):
def __init__(self,PdfPreviewObj ):
self.PdfPreviewObj =PdfPreviewObj
self.setupUi(PdfPreviewObj)
self.PdfPreviewObj.show()
self.pushButtonOpenFolder.clicked.connect(self.setExistingDirectory)
def setExistingDirectory(self,qf):
options = QFileDialog.DontResolveSymlinks | QFileDialog.ShowDirsOnly
directory = QFileDialog.getExistingDirectory(self,
"Open Folder",
options=options)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
PdfPreviewWindow = QtWidgets.QMainWindow()
pdfViewerUi = pdfViewer(PdfPreviewWindow)
sys.exit(app.exec_())