当前位置: 首页 > news >正文

Pyside6 QFileDialog

Pyside6 QFileDialog

  • Pyside6 QFileDialog
    • 常用函数
      • getOpenFileName
      • getOpenFileNames
      • getExistingDirectory
      • getSaveFileName
    • 程序
      • 界面程序
      • 主程序

Pyside6 QFileDialog提供了一个允许用户选择文件或目录的对话框。关于QFileDialog的使用可以参考下面的文档

https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QFileDialog.html#qfiledialog

Pyside6 QFileDialog

常用函数

函数作用
getOpenFileName打开单个已存在的文件
getOpenFileNames打开多个已存在的文件
getSaveFileName打开需要保存的文件
getExistingDirectory打开已存在的文件夹

getOpenFileName

getOpenFileName是打开一个已经存在的文件,如果文件存在就返回该文件的文件路径,如果不存在就返回空。

static PySide6.QtWidgets.QFileDialog.getOpenFileName([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])# parent:父组件
# caption:对话框的标题
# dir:默认路径 比如在windows下默认选择C盘则应该为 'C:\\'
# filter:话框的后缀名过滤器 比如筛选txt和bin文件 图像文件 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)'
# selectedFilter:默认选择的过滤器
# options:参数
'''
options参数可选ShowDirsOnly             : QFileDialog.Option = ... # 0x1DontResolveSymlinks      : QFileDialog.Option = ... # 0x2DontConfirmOverwrite     : QFileDialog.Option = ... # 0x4DontUseNativeDialog      : QFileDialog.Option = ... # 0x8ReadOnly                 : QFileDialog.Option = ... # 0x10HideNameFilterDetails    : QFileDialog.Option = ... # 0x20DontUseCustomDirectoryIcons: QFileDialog.Option = ... # 0x40可用|运算符进行组合
'''
file =  QFileDialog.getOpenFileName(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件

在这里插入图片描述

getOpenFileNames

getOpenFileNames是打开多个已经存在的文件,如果文件存在就返回该文件的文件路径,如果不存在就返回空。

static PySide6.QtWidgets.QFileDialog.getOpenFileNames([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])# parent:父组件
# caption:对话框的标题
# dir:默认路径 比如在windows下默认选择C盘则应该为 'C:\\'
# 话框的后缀名过滤器 比如筛选txt和bin文件 图像文件 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)'
# selectedFilter:默认选择的过滤器
# options:参数
'''
options参数可选ShowDirsOnly             : QFileDialog.Option = ... # 0x1DontResolveSymlinks      : QFileDialog.Option = ... # 0x2DontConfirmOverwrite     : QFileDialog.Option = ... # 0x4DontUseNativeDialog      : QFileDialog.Option = ... # 0x8ReadOnly                 : QFileDialog.Option = ... # 0x10HideNameFilterDetails    : QFileDialog.Option = ... # 0x20DontUseCustomDirectoryIcons: QFileDialog.Option = ... # 0x40可用|运算符进行组合
'''
file =  QFileDialog.getOpenFileNames(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件

在这里插入图片描述

getExistingDirectory

getExistingDirectory是打开单个已存在的文件夹,如果文件夹存在就返回该文件夹的的路径,如果不存在就返回空。

static PySide6.QtWidgets.QFileDialog.getExistingDirectory([parent=None[, caption=""[, dir=""[, options=QFileDialog.Option.ShowDirsOnly]]]])# parent:父组件
# caption:对话框的标题
# dir:默认路径 比如在windows下默认选择C盘则应该为 'C:\\'
# options:参数
'''
options参数可选ShowDirsOnly             : QFileDialog.Option = ... # 0x1DontResolveSymlinks      : QFileDialog.Option = ... # 0x2DontConfirmOverwrite     : QFileDialog.Option = ... # 0x4DontUseNativeDialog      : QFileDialog.Option = ... # 0x8ReadOnly                 : QFileDialog.Option = ... # 0x10HideNameFilterDetails    : QFileDialog.Option = ... # 0x20DontUseCustomDirectoryIcons: QFileDialog.Option = ... # 0x40可用|运算符进行组合
'''
file =  QFileDialog.getExistingDirectory(self, "选择文件夹","",QFileDialog.ShowDirsOnly| QFileDialog.DontResolveSymlinks)

在这里插入图片描述

getSaveFileName

getSaveFileName是获取需要保存文件的文件名,此函数不会帮你创建文件,该函数允许返回不存在的文件路径,调用成功后该函数会返回文件的路径,如果取消则返回空。

static PySide6.QtWidgets.QFileDialog.getSaveFileName([parent=None[, caption=""[, dir=""[, filter=""[, selectedFilter=""[, options=QFileDialog.Options()]]]]]])# parent:父组件
# caption:对话框的标题
# dir:默认路径 比如在windows下默认选择C盘则应该为 'C:\\'
# 话框的后缀名过滤器 比如筛选txt和bin文件 图像文件 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)'
# selectedFilter:默认选择的过滤器
# options:参数
'''
options参数可选ShowDirsOnly             : QFileDialog.Option = ... # 0x1DontResolveSymlinks      : QFileDialog.Option = ... # 0x2DontConfirmOverwrite     : QFileDialog.Option = ... # 0x4DontUseNativeDialog      : QFileDialog.Option = ... # 0x8ReadOnly                 : QFileDialog.Option = ... # 0x10HideNameFilterDetails    : QFileDialog.Option = ... # 0x20DontUseCustomDirectoryIcons: QFileDialog.Option = ... # 0x40可用|运算符进行组合
'''
file  = QFileDialog.getSaveFileName(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件

在这里插入图片描述

程序

界面程序

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"><class>MainWindow</class><widget class="QMainWindow" name="MainWindow"><property name="geometry"><rect><x>0</x><y>0</y><width>444</width><height>331</height></rect></property><property name="windowTitle"><string>MainWindow</string></property><widget class="QWidget" name="centralwidget"><layout class="QVBoxLayout" name="verticalLayout_2"><item><widget class="QTabWidget" name="tabWidget"><property name="currentIndex"><number>0</number></property><widget class="QWidget" name="tab"><attribute name="title"><string>getOpenFileName</string></attribute><layout class="QVBoxLayout" name="verticalLayout_3"><item><layout class="QVBoxLayout" name="verticalLayout"><property name="leftMargin"><number>120</number></property><item><widget class="QPushButton" name="pushButton_2"><property name="maximumSize"><size><width>150</width><height>16777215</height></size></property><property name="text"><string>选择单个文件</string></property></widget></item></layout></item><item><layout class="QHBoxLayout" name="horizontalLayout"><item><widget class="QLineEdit" name="lineEdit"><property name="font"><font><pointsize>10</pointsize></font></property></widget></item></layout></item></layout></widget><widget class="QWidget" name="tab_2"><attribute name="title"><string>getOpenFileNames</string></attribute><layout class="QVBoxLayout" name="verticalLayout_6"><item><layout class="QVBoxLayout" name="verticalLayout_4"><property name="leftMargin"><number>120</number></property><item><widget class="QPushButton" name="pushButton_3"><property name="maximumSize"><size><width>150</width><height>16777215</height></size></property><property name="text"><string>选择多个文件</string></property></widget></item></layout></item><item><layout class="QVBoxLayout" name="verticalLayout_5"><item><widget class="QTextEdit" name="textEdit"/></item></layout></item></layout></widget><widget class="QWidget" name="tab_3"><attribute name="title"><string>getExistingDirectory</string></attribute><layout class="QVBoxLayout" name="verticalLayout_8"><item><layout class="QVBoxLayout" name="verticalLayout_7"><property name="leftMargin"><number>120</number></property><item><widget class="QPushButton" name="pushButton_5"><property name="maximumSize"><size><width>150</width><height>16777215</height></size></property><property name="text"><string>选择文件夹</string></property></widget></item></layout></item><item><layout class="QHBoxLayout" name="horizontalLayout_2"><item><widget class="QLineEdit" name="lineEdit_2"><property name="font"><font><pointsize>10</pointsize></font></property></widget></item></layout></item></layout></widget><widget class="QWidget" name="tab_4"><attribute name="title"><string>getSaveFileName</string></attribute><layout class="QVBoxLayout" name="verticalLayout_9"><item><layout class="QHBoxLayout" name="horizontalLayout_3"><item><widget class="QPushButton" name="pushButton"><property name="maximumSize"><size><width>150</width><height>16777215</height></size></property><property name="text"><string>选择要保存的文件</string></property></widget></item></layout></item><item><layout class="QHBoxLayout" name="horizontalLayout_4"><item><widget class="QLineEdit" name="lineEdit_3"/></item></layout></item></layout></widget></widget></item></layout></widget><widget class="QMenuBar" name="menubar"><property name="geometry"><rect><x>0</x><y>0</y><width>444</width><height>22</height></rect></property></widget><widget class="QStatusBar" name="statusbar"/></widget><resources/><connections/>
</ui>

主程序

# Import Qt libraries
from PySide6.QtWidgets import *
from PySide6.QtCore import QFile,Qt,QTimer
# Import UI developed in Qt Creator
from FileDialog_ui import Ui_MainWindow  # 导入界面
# Import PseudoSensor
# Import system tools and datetime
import sys
import statistics
import time
from datetime import datetime
from PySide6 import QtGui, QtWidgets
from PySide6.QtGui import QIcon, QPixmap, QMovie, QPainter, QBrush, QPen,QColor,QPalette,QFont,QImage,QPixmap
import random# Create and start the Qt application
class MainWindow(QMainWindow):def __init__(self):super(MainWindow, self).__init__()# 设置界面为用户设计的界面self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.pushButton_2.clicked.connect(self.getOpenFileName)self.ui.pushButton_3.clicked.connect(self.getOpenFileNames)self.ui.pushButton_5.clicked.connect(self.getExistingDirectory)self.ui.pushButton.clicked.connect(self.getSaveFileName)def getOpenFileName(self):file  = QFileDialog.getOpenFileName(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件self.ui.lineEdit.setText(file[0])print(file)def getOpenFileNames(self):file  = QFileDialog.getOpenFileNames(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件self.ui.textEdit.setText(str(file[0]))print(file)def getSaveFileName(self):file  = QFileDialog.getSaveFileName(parent =  None, caption =  '请选择选择文件',  dir = '',filter = 'file(*.txt *.bin) ;;image(*.jpg *.bmp *.png *.gif)') # 选择后缀为.txt .bin的文件 和.jpg .bmp .png .gif的图像文件self.ui.lineEdit_3.setText(file[0])print(file)def getExistingDirectory(self):file = QFileDialog.getExistingDirectory(self, "选择文件夹","",QFileDialog.ShowDirsOnly| QFileDialog.DontResolveSymlinks)self.ui.lineEdit_2.setText(file)print(file)def closeAndExit(self):sys.exit()if __name__ == "__main__":app = QApplication(sys.argv) # 初始化QApplication# 初始化界面并显示界面window = MainWindow() window.show() window.setFixedSize(window.width(), window.height())sys.exit(app.exec())

相关文章:

Pyside6 QFileDialog

Pyside6 QFileDialog Pyside6 QFileDialog常用函数getOpenFileNamegetOpenFileNamesgetExistingDirectorygetSaveFileName 程序界面程序主程序 Pyside6 QFileDialog提供了一个允许用户选择文件或目录的对话框。关于QFileDialog的使用可以参考下面的文档 https://doc.qt.io/qtfo…...

Leetcode1793. Maximum Score of a Good Subarray

给定一个数组和一个下标 k k k 子数组 ( i , j ) (i,j) (i,j)分数定义为 min ⁡ ( n u m s [ i ] , n u m s [ i 1 ] , ⋯ , n u m s [ j ] ) ∗ ( j − i 1 ) \min\left(nums[i], nums[i 1],\cdots, nums[j]\right)*\left(j-i1\right) min(nums[i],nums[i1],⋯,nums[j])∗(…...

只需五步,在Linux安装chrome及chromedriver(CentOS)

一、安装Chrome 1&#xff09;先执行命令下载chrome&#xff1a; wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm2&#xff09;安装chrome yum localinstall google-chrome-stable_current_x86_64.rpm看到下图中的Complete出现则代表安装…...

第01章-Java语言概述

目录 1 常见DOS命令 常用指令 相对路径与绝对路径 2 转义字符 3 安装JDK与配置环境变量 JDK与JRE JDK的版本 JDK的下载 JDK的安装 配置path环境变量 4 Java程序的编写与执行 5 Java注释 6 Java API文档 7 Java核心机制&#xff1a;JVM 1 常见DOS命令 DOS&#xff08;…...

Spring | Spring Cache 缓存框架

Spring Cache 缓存框架&#xff1a; Spring Cache功能介绍Spring Cache的Maven依赖Spring Cache的常用注解EnableCaching注解CachePut注解Cacheable注解CacheEvict注解 Spring Cache功能介绍 Spring Cache是Spring的一个框架&#xff0c;实现了基于注解的缓存功能。只需简单加一…...

雷达开发的基本概念fft,cfar,以及Clutter, CFAR,AoA

CFAR Constant False-Alarm Rate的缩写。在雷达信号检测中&#xff0c;当外界干扰强度变化时&#xff0c;雷达能自动调整其灵敏度&#xff0c;使雷达的虚警概率保持不变。具有这种特性的接收机称为恒虚警接收机。雷达信号的检测总是在干扰背景下进行的&#xff0c;这些干扰包括…...

什么是大数据测试?有哪些类型?应该怎么测?

随着目前世界上各个国家使用大数据应用程序或应用大数据技术场景的数量呈指数增长&#xff0c;相应的&#xff0c;对于测试大数据应用时所需的知识与大数据测试工程师的需求也在同步增加。 针对大数据测试的相关技术已慢慢成为当下软件测试人员需要了解和掌握的一门通用技术。…...

03-垃圾收集策略与算法

垃圾收集策略与算法 程序计数器、虚拟机栈、本地方法栈随线程而生&#xff0c;也随线程而灭&#xff1b;栈帧随着方法的开始而入栈&#xff0c;随着方法的结束而出栈。这几个区域的内存分配和回收都具有确定性&#xff0c;在这几个区域内不需要过多考虑回收的问题&#xff0c;因…...

1.AUTOSAR的架构及方法论

在15、16年之前,AUTOSAR这个东西其实是被国内很多大的OEM或者供应商所排斥的。为什么?最主要的原因还是以前采用手写底层代码+应用层模型生成代码的方式进行开发。每个供应商或者OEM都有自己的软件规范或者技术壁垒,现在提个AUTOSAR想搞统一,用一个规范来收割汽车软件供应链…...

Kotlin中的List集合

在Kotlin中&#xff0c;List集合用于存储一组有序的元素。List集合分为可变集合&#xff08;MutableList&#xff09;和不可变集合&#xff08;List&#xff09;。本篇博客将分别介绍可变集合和不可变集合&#xff0c;并提供相关的API示例代码。 不可变集合&#xff08;List&a…...

微信小程序WeUI项目weui-miniprogram如何运行起来?

微信小程序WeUI项目weui-miniprogram如何运行起来&#xff1f; 解决方法: 1、下载 https://github.com/wechat-miniprogram/weui-miniprogram 2、在项目根目录weui-miniprogram-master执行以下命令安装依赖&#xff1a; npm install 3、继续执行编译命令&#xff1a; npm r…...

MapReduce编程:检索特定群体搜索记录和定义分片操作

文章目录 MapReduce 编程&#xff1a;检索特定群体搜索记录和定义分片操作一、实验目标二、实验要求及注意事项三、实验内容及步骤 附&#xff1a;系列文章 MapReduce 编程&#xff1a;检索特定群体搜索记录和定义分片操作 一、实验目标 熟悉MapReduce编程涉及的主要类和接口…...

pytorch 入门 (四)案例二:人脸表情识别-VGG16实现

实战教案二&#xff1a;人脸表情识别-VGG16实现 本文为&#x1f517;小白入门Pytorch内部限免文章 参考本文所写记录性文章&#xff0c;请在文章开头注明以下内容&#xff0c;复制粘贴即可 &#x1f368; 本文为&#x1f517;小白入门Pytorch中的学习记录博客&#x1f366; 参…...

数据结构--线性表回顾

目录 线性表 1.定义 2.线性表的基本操作 3.顺序表的定义 3.1顺序表的实现--静态分配 3.2顺序表的实现--动态分配 4顺序表的插入、删除 4.1插入操作的时间复杂度 4.2顺序表的删除操作-时间复杂度 5 顺序表的查找 5.1按位查找 5.2 动态分配的方式 5.3按位查找的时间…...

ChatGPT(1):ChatGPT初识

1 ChatGPT原理 ChatGPT 是基于 GPT-3.5 架构的一个大型语言模型&#xff0c;它的工作原理涵盖了深度学习和自然语言处理技术。以下是 ChatGPT 的工作原理的一些关键要点&#xff1a; 神经网络架构&#xff1a;ChatGPT 的核心是一个深度神经网络&#xff0c;采用了变种的 Tran…...

PostgreSQL 插件 CREATE EXTENSION 原理

PostgreSQL 提供了丰富的数据库内核编程接口&#xff0c;允许开发者在不修改任何 Postgres 核心代码的情况下以插件的形式将自己的代码融入内核&#xff0c;扩展数据库功能。本文探究了 PostgreSQL 插件的一般源码组成&#xff0c;梳理插件的源码内容和实现方式&#xff1b;并介…...

Android常见分区

一、Google官方标准分区 1. Boot分区 包含Linux内核和一个最小的root文件系统(装载到ramdisk中)&#xff0c;用于挂载系统和其他的分区并开始Runtime。正如名字所代表的意思&#xff08;注&#xff1a;boot的意思是启动&#xff09;&#xff0c;这个分区使Android设备可以启动…...

华为鸿蒙4谷歌GMS安装教学

目录 问题描述 参考视频 教学视频1 配套文档 教学视频2 资源包(配套视频1) 设备未经 play 保护机制认证 问题描述 很多国外的最新应用需要再Google商店才能下载比如ChatGPT 华为手机不支持 Google Play 服务的原因主要是由于谷歌服务框架&#xff08;GMS&#xff09;未…...

原型设计工具:Balsamiq Wireframes 4.7.4 Crack

原型设计工具:Balsamiq Wireframes是一种快速的低保真UI 线框图工具&#xff0c;可重现在记事本或白板上绘制草图但使用计算机的体验。 它确实迫使您专注于结构和内容&#xff0c;避免在此过程后期对颜色和细节进行冗长的讨论。 线框速度很快&#xff1a;您将产生更多想法&am…...

Nginx Proxy代理

代理原理 反向代理产生的背景&#xff1a; 在计算机世界里&#xff0c;由于单个服务器的处理客户端&#xff08;用户&#xff09;请求能力有一个极限&#xff0c;当用户的接入请求蜂拥而入时&#xff0c;会造成服务器忙不过来的局面&#xff0c;可以使用多个服务器来共同分担成…...

java_网络服务相关_gateway_nacos_feign区别联系

1. spring-cloud-starter-gateway 作用&#xff1a;作为微服务架构的网关&#xff0c;统一入口&#xff0c;处理所有外部请求。 核心能力&#xff1a; 路由转发&#xff08;基于路径、服务名等&#xff09;过滤器&#xff08;鉴权、限流、日志、Header 处理&#xff09;支持负…...

【配置 YOLOX 用于按目录分类的图片数据集】

现在的图标点选越来越多&#xff0c;如何一步解决&#xff0c;采用 YOLOX 目标检测模式则可以轻松解决 要在 YOLOX 中使用按目录分类的图片数据集&#xff08;每个目录代表一个类别&#xff0c;目录下是该类别的所有图片&#xff09;&#xff0c;你需要进行以下配置步骤&#x…...

三体问题详解

从物理学角度&#xff0c;三体问题之所以不稳定&#xff0c;是因为三个天体在万有引力作用下相互作用&#xff0c;形成一个非线性耦合系统。我们可以从牛顿经典力学出发&#xff0c;列出具体的运动方程&#xff0c;并说明为何这个系统本质上是混沌的&#xff0c;无法得到一般解…...

Android15默认授权浮窗权限

我们经常有那种需求&#xff0c;客户需要定制的apk集成在ROM中&#xff0c;并且默认授予其【显示在其他应用的上层】权限&#xff0c;也就是我们常说的浮窗权限&#xff0c;那么我们就可以通过以下方法在wms、ams等系统服务的systemReady()方法中调用即可实现预置应用默认授权浮…...

GO协程(Goroutine)问题总结

在使用Go语言来编写代码时&#xff0c;遇到的一些问题总结一下 [参考文档]&#xff1a;https://www.topgoer.com/%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B/goroutine.html 1. main()函数默认的Goroutine 场景再现&#xff1a; 今天在看到这个教程的时候&#xff0c;在自己的电…...

怎么让Comfyui导出的图像不包含工作流信息,

为了数据安全&#xff0c;让Comfyui导出的图像不包含工作流信息&#xff0c;导出的图像就不会拖到comfyui中加载出来工作流。 ComfyUI的目录下node.py 直接移除 pnginfo&#xff08;推荐&#xff09;​​ 在 save_images 方法中&#xff0c;​​删除或注释掉所有与 metadata …...

探索Selenium:自动化测试的神奇钥匙

目录 一、Selenium 是什么1.1 定义与概念1.2 发展历程1.3 功能概述 二、Selenium 工作原理剖析2.1 架构组成2.2 工作流程2.3 通信机制 三、Selenium 的优势3.1 跨浏览器与平台支持3.2 丰富的语言支持3.3 强大的社区支持 四、Selenium 的应用场景4.1 Web 应用自动化测试4.2 数据…...

沙箱虚拟化技术虚拟机容器之间的关系详解

问题 沙箱、虚拟化、容器三者分开一一介绍的话我知道他们各自都是什么东西&#xff0c;但是如果把三者放在一起&#xff0c;它们之间到底什么关系&#xff1f;又有什么联系呢&#xff1f;我不是很明白&#xff01;&#xff01;&#xff01; 就比如说&#xff1a; 沙箱&#…...

【Linux】Linux安装并配置RabbitMQ

目录 1. 安装 Erlang 2. 安装 RabbitMQ 2.1.添加 RabbitMQ 仓库 2.2.安装 RabbitMQ 3.配置 3.1.启动和管理服务 4. 访问管理界面 5.安装问题 6.修改密码 7.修改端口 7.1.找到文件 7.2.修改文件 1. 安装 Erlang 由于 RabbitMQ 是用 Erlang 编写的&#xff0c;需要先安…...

工厂方法模式和抽象工厂方法模式的battle

1.案例直接上手 在这个案例里面&#xff0c;我们会实现这个普通的工厂方法&#xff0c;并且对比这个普通工厂方法和我们直接创建对象的差别在哪里&#xff0c;为什么需要一个工厂&#xff1a; 下面的这个是我们的这个案例里面涉及到的接口和对应的实现类&#xff1a; 两个发…...