当前位置: 首页 > 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;可以使用多个服务器来共同分担成…...

无法与IP建立连接,未能下载VSCode服务器

如题&#xff0c;在远程连接服务器的时候突然遇到了这个提示。 查阅了一圈&#xff0c;发现是VSCode版本自动更新惹的祸&#xff01;&#xff01;&#xff01; 在VSCode的帮助->关于这里发现前几天VSCode自动更新了&#xff0c;我的版本号变成了1.100.3 才导致了远程连接出…...

【Redis技术进阶之路】「原理分析系列开篇」分析客户端和服务端网络诵信交互实现(服务端执行命令请求的过程 - 初始化服务器)

服务端执行命令请求的过程 【专栏简介】【技术大纲】【专栏目标】【目标人群】1. Redis爱好者与社区成员2. 后端开发和系统架构师3. 计算机专业的本科生及研究生 初始化服务器1. 初始化服务器状态结构初始化RedisServer变量 2. 加载相关系统配置和用户配置参数定制化配置参数案…...

cf2117E

原题链接&#xff1a;https://codeforces.com/contest/2117/problem/E 题目背景&#xff1a; 给定两个数组a,b&#xff0c;可以执行多次以下操作&#xff1a;选择 i (1 < i < n - 1)&#xff0c;并设置 或&#xff0c;也可以在执行上述操作前执行一次删除任意 和 。求…...

【2025年】解决Burpsuite抓不到https包的问题

环境&#xff1a;windows11 burpsuite:2025.5 在抓取https网站时&#xff0c;burpsuite抓取不到https数据包&#xff0c;只显示&#xff1a; 解决该问题只需如下三个步骤&#xff1a; 1、浏览器中访问 http://burp 2、下载 CA certificate 证书 3、在设置--隐私与安全--…...

Matlab | matlab常用命令总结

常用命令 一、 基础操作与环境二、 矩阵与数组操作(核心)三、 绘图与可视化四、 编程与控制流五、 符号计算 (Symbolic Math Toolbox)六、 文件与数据 I/O七、 常用函数类别重要提示这是一份 MATLAB 常用命令和功能的总结,涵盖了基础操作、矩阵运算、绘图、编程和文件处理等…...

HDFS分布式存储 zookeeper

hadoop介绍 狭义上hadoop是指apache的一款开源软件 用java语言实现开源框架&#xff0c;允许使用简单的变成模型跨计算机对大型集群进行分布式处理&#xff08;1.海量的数据存储 2.海量数据的计算&#xff09;Hadoop核心组件 hdfs&#xff08;分布式文件存储系统&#xff09;&a…...

在Ubuntu24上采用Wine打开SourceInsight

1. 安装wine sudo apt install wine 2. 安装32位库支持,SourceInsight是32位程序 sudo dpkg --add-architecture i386 sudo apt update sudo apt install wine32:i386 3. 验证安装 wine --version 4. 安装必要的字体和库(解决显示问题) sudo apt install fonts-wqy…...

无人机侦测与反制技术的进展与应用

国家电网无人机侦测与反制技术的进展与应用 引言 随着无人机&#xff08;无人驾驶飞行器&#xff0c;UAV&#xff09;技术的快速发展&#xff0c;其在商业、娱乐和军事领域的广泛应用带来了新的安全挑战。特别是对于关键基础设施如电力系统&#xff0c;无人机的“黑飞”&…...

LabVIEW双光子成像系统技术

双光子成像技术的核心特性 双光子成像通过双低能量光子协同激发机制&#xff0c;展现出显著的技术优势&#xff1a; 深层组织穿透能力&#xff1a;适用于活体组织深度成像 高分辨率观测性能&#xff1a;满足微观结构的精细研究需求 低光毒性特点&#xff1a;减少对样本的损伤…...

tomcat入门

1 tomcat 是什么 apache开发的web服务器可以为java web程序提供运行环境tomcat是一款高效&#xff0c;稳定&#xff0c;易于使用的web服务器tomcathttp服务器Servlet服务器 2 tomcat 目录介绍 -bin #存放tomcat的脚本 -conf #存放tomcat的配置文件 ---catalina.policy #to…...