美文网首页
PyQt5的QFileDialog

PyQt5的QFileDialog

作者: 满庭芳里买楚楚 | 来源:发表于2017-12-15 23:08 被阅读0次

使用方式:

selectedFile = QFileDialog.getOpenFileName(self,
                "Select one file to open",
                "/home",'Docement ( *.pdf )')
其调用结果为 image.png

此外,返回值selectedFile 是一个元组(显示在plaintext里面):


image.png

源代码为:

 selectedFile = QFileDialog.getOpenFileName(self, "Select one file to open",    
      "/home","Docement ( *.pdf )")
 self.plainTextEdit.appendPlainText( str( len(selectedFile) ) )
 self.plainTextEdit.appendPlainText( str( selectedFile ) )

选择多个文件的对话框使用方式为:

selectedFiles = QFileDialog.getOpenFileNames(self,
                "Select one file to open",
                "/home",'Docement ( *.pdf )')
image.png

此时运行结果为:


image.png

selectedFiles 依旧是两个元素的元组,但是第一个元素变为了文件路径的列表

相关文章

网友评论

      本文标题:PyQt5的QFileDialog

      本文链接:https://www.haomeiwen.com/subject/pesjwxtx.html