pyqt5生成py的文件为什么是c 语言,如何使用PyQt5在python中创建文件对话框
我有一個名為PDFviewer的python類,在運行該程序時,系統將顯示一個窗口,該窗口處理button(打開文件夾),它將打開一個文件對話框,允許用戶選擇一個目錄并顯示其中的文件。在
問題是,當我嘗試單擊按鈕時,系統崩潰并顯示以下錯誤:File
"C:\Users\test\Documents\Python_Projects\final_project\myPDFviewer.py",
line 36, in sys.exit(app.exec_()) File
"C:\Users\test\Documents\Python_Projects\final_project\myPDFviewer.py",
line 24, in setExistingDirectory options=options)
builtins.TypeError: getExistingDirectory(parent: QWidget = None,
caption: str = '', directory: str = '', options:
Union[QFileDialog.Options, QFileDialog.Option] =
QFileDialog.ShowDirsOnly): argument 1 has unexpected type '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_())
總結
以上是生活随笔為你收集整理的pyqt5生成py的文件为什么是c 语言,如何使用PyQt5在python中创建文件对话框的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 线性回归 —— python
- 下一篇: 用html编写一幅简单的画,使用html