pyqt6:QMessageBox 、QInputDialog、QFileDialog弹窗

部署运行你感兴趣的模型镜像

目录

一、准备步骤

二、代码


 一、准备步骤

先在qtdesigner拖入一个pushButton。然后保存项目命名为test.ui。

 用pyuic生成test.py文件。再创建load_test.py文件,写代码如下:

二、代码

import sys
from test import Ui_Form

import warnings
warnings.filterwarnings('ignore')

from PyQt6.QtWidgets import *


class MyApp(QWidget, Ui_Form):

    def __init__(self):
        super(MyApp, self).__init__()
        self.setupUi(self)

        self.pushButton.clicked.connect(self.say)

    def say(self):
        # region QMessageBox
        QMessageBox.information(self, "提示", "这是一个信息消息。")
        QMessageBox.warning(self, "警告", "这是一个警告消息。")
        QMessageBox.critical(self, "错误", "这是一个错误消息。")
        QMessageBox.about(self, '关于', '这是关于软件的说明。。。')

        choice = QMessageBox.question(self, "问题", "是否继续?", QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No)
        if choice == QMessageBox.StandardButton.Yes:
            print("用户点击了'是'")
        else:
            print("用户点击了'否'")
        # endregion

        # region QInputDialog
        value, sure = QInputDialog.getInt(self, '输入整数', '值', min=0, max=20)
        if sure:
            print(value)

        value, sure = QInputDialog.getDouble(self, '输入小数', '值', min=0, max=20)
        if sure:
            print(value)

        value, sure = QInputDialog.getText(self, '输入字符串', '值', text='')
        if sure:
            print(value)


        value, sure = QInputDialog.getMultiLineText(self, '输入整数', '值', '')
        if sure:
            print(value)

        seasons = ['春', '夏', '秋', '东']
        value, sure = QInputDialog.getItem(self, '选择季节', '值', seasons, current=0, editable=False)  # 我这里不能写items=seasons,只能seasons,不然会报错,莫名其妙的
        if sure:
            print(value)
        # endregion

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

        file_, _ = QFileDialog.getOpenFileName(self, "选取文件", "C:/", "All Files (*);;Text Files (*.txt)")  # 文件扩展名用双分号间隔
        print(file_)

        file_, _ = QFileDialog.getSaveFileName(self, "文件保存", "C:/", "All Files (*);;Text Files (*.txt)")
        print(file_)
        # endregion


if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MyApp()
    w.show()
    sys.exit(app.exec())

感受吧

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

learninger_lt7

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值