• pyqt QFileDialog


    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,
                      "选取文件夹",
                      "./")                 #起始路径
        print(directory1)
     
        fileName1, filetype = QFileDialog.getOpenFileName(self,
                      "选取文件",
                      "./",
                      "All Files (*);;Text Files (*.txt)")  #设置文件扩展名过滤,注意用双分号间隔
        print(fileName1,filetype)
     
        files, ok1 = QFileDialog.getOpenFileNames(self,
                      "多文件选择",
                      "./",
                      "All Files (*);;Text Files (*.txt)")
        print(files,ok1)
     
        fileName2, ok2 = QFileDialog.getSaveFileName(self,
                      "文件保存",
                      "./",
                      "All Files (*);;Text Files (*.txt)")
     
    if __name__=="__main__":
      import sys
     
      app=QtWidgets.QApplication(sys.argv)
      myshow=MyWindow()
      myshow.show()
      sys.exit(app.exec_())

  • 相关阅读:
    Windows10 ntoskrnl.exe占用大量的磁盘空间(100%)
    Windows10 正式企业版激活
    edit-distance
    climbing-stairs
    minimum-path-sum
    unique-paths-II
    unique-paths
    剑指 Offer 42. 连续子数组的最大和
    剑指 Offer 54. 二叉搜索树的第k大节点
    矩阵中的路径
  • 原文地址:https://www.cnblogs.com/zhoug2020/p/9041279.html
Copyright © 2020-2023  润新知