码迷,mamicode.com
首页 > 其他好文 > 详细

PyQt5学习笔记09----标准文件打开保存框QFileDialog

时间:2015-04-21 11:21:10      阅读:1197      评论:0      收藏:0      [点我收藏+]

标签:python   pyqt5   

单个文件打开 QFileDialog.getOpenFileName()

多个文件打开 QFileDialog.getOpenFileNames()

文件夹选取     QFileDialog.getExistingDirectory()

文件保存         QFileDialog.getSaveFileName()

from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QFileDialog

class MyWindow(QtWidgets.QWidget):
    def __init__(self):
        super(MyWindow,self).__init__()
        self.myButton = QtWidgets.QPushButton(self)
        self.myButton.setObjectName("myButton")
        self.myButton.setText("Test")
        self.myButton.clicked.connect(self.msg)

    def msg(self):
        directory1 = QFileDialog.getExistingDirectory(self,
                                    "选取文件夹",
                                    "C:/")                                 #起始路径
        print(directory1)

        fileName1, filetype = QFileDialog.getOpenFileName(self,
                                    "选取文件",
                                    "C:/",
                                    "All Files (*);;Text Files (*.txt)")   #设置文件扩展名过滤,注意用双分号间隔
        print(fileName1,filetype)

        files, ok1 = QFileDialog.getOpenFileNames(self,
                                    "多文件选择",
                                    "C:/",
                                    "All Files (*);;Text Files (*.txt)")
        print(files,ok1)

        fileName2, ok2 = QFileDialog.getSaveFileName(self,
                                    "文件保存",
                                    "C:/",
                                    "All Files (*);;Text Files (*.txt)")

if __name__=="__main__":  
    import sys  
  
    app=QtWidgets.QApplication(sys.argv)  
    myshow=MyWindow()
    myshow.show()
    sys.exit(app.exec_())  


PyQt5学习笔记09----标准文件打开保存框QFileDialog

标签:python   pyqt5   

原文地址:http://blog.csdn.net/a359680405/article/details/45166271

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!