# -*- coding: utf-8 -*-
import os
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5 import QtWidgets
class Ui_MainWindow(QtWidgets.QMainWindow):
def setupUi(self):
self.setObjectName("MainWindow")
self.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.choose_file = QtWidgets.QPushButton(self.centralwidget)
self.choose_file.setGeometry(QtCore.QRect(180, 20, 301, 81))
self.choose_file.setObjectName("choose_file")
self.choose_mutifile = QtWidgets.QPushButton(self.centralwidget)
self.choose_mutifile.setGeometry(QtCore.QRect(180, 110, 301, 81))
self.choose_mutifile.setObjectName("choose_mutifile")
self.choose_dir = QtWidgets.QPushButton(self.centralwidget)
self.choose_dir.setGeometry(QtCore.QRect(180, 200, 301, 91))
self.choose_dir.setObjectName("choose_dir")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(180, 300, 301, 91))
self.pushButton_4.setObjectName("pushButton_4")
self.menubar = QtWidgets.QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 30))
self.menubar.setObjectName("menubar")
self.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(self)
self.statusbar.setObjectName("statusbar")
self.setStatusBar(self.statusbar)
self.setCentralWidget(self.centralwidget)
self.set_connect()
self.retranslateUi()
QtCore.QMetaObject.connectSlotsByName(self)
def set_connect(self):
self.choose_file.clicked.connect(self.slot_chooseFile)
self.choose_mutifile.clicked.connect(self.slot_btn_chooseMutiFile)
self.choose_dir.clicked.connect(self.slot_btn_chooseDir)
self.pushButton_4.clicked.connect(self.slot_btn_saveFile)
def slot_chooseFile(self): # 槽函数
fileName, fileType = QtWidgets.QFileDialog.getOpenFileName(self, "选取文件", os.getcwd(),
"All Files(*);;Text Files(*.txt *.log)")
print(fileName)
print(fileType)
if fileName_choose == "":
print("\n取消选择")
return
def slot_btn_chooseMutiFile(self):
files, filetype = QFileDialog.getOpenFileNames(self,
"多文件选择", os.getcwd(),
"All Files (*);;PDF Files (*.pdf);;Text Files (*.txt *.log)")
if len(files) == 0:
print("\n取消选择")
return
print("\n你选择的文件为:")
for file in files:
print(file)
print("文件筛选器类型: ", filetype)
def slot_btn_saveFile(self):
fileName_choose, filetype = QFileDialog.getSaveFileName(self, "文件保存", os.getcwd(),
"All Files (*);;Text Files (*.txt)")
if fileName_choose == "":
print("\n取消选择")
return
print("\n你选择要保存的文件为:")
print(fileName_choose)
print("文件筛选器类型: ", filetype)
def slot_btn_chooseDir(self):
dir_choose = QFileDialog.getExistingDirectory(None, "选取文件夹", "")
if dir_choose == "":
print("\n取消选择")
else:
print("\n你选择的文件夹为:")
print(dir_choose)
def retranslateUi(self):
_translate = QtCore.QCoreApplication.translate
self.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.choose_file.setText(_translate("MainWindow", "选择文件"))
self.choose_mutifile.setText(_translate("MainWindow", "选择多个文件"))
self.choose_dir.setText(_translate("MainWindow", "选择目录"))
self.pushButton_4.setText(_translate("MainWindow", "保存文件"))
if __name__ == "__main__":
[pyqt5]选择文件选择多个文件选择目录保存文件
原创
©著作权归作者所有:来自51CTO博客作者futureflsl的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
目录和文件管理
文件、目录权限r:可读 w:可写 x:可执行 4 2 1(第一
文件名 解压缩 vi编辑器 -
python pyqt5 文件夹选择 pyqt5选择文件路径窗口
单个文件打开 QFileDialog.getOpenFileName()多个文件打开 QFileDialog.getOpenFileNames()文件夹选取 QFileDialog.getExistingDirectory()文件保存 QFileDialog.getSaveFileName()打开多个文件 PyQt5中的打开文件对话框,选择文件后返回的是文件的文件路径而不是打开文件
python pyqt5 文件夹选择 PyQt5文件对话框 PyQt5打开多个文件 PyQt5打开文件 打开文件