4月2日 qt密码生成小程序(可选择生成密码的格式),基于Python框架下的pyqt6

4月2日 密码生成小程序

代码展示:

import string

from PyQt6.QtWidgets import (
    QApplication, QDialog,QMessageBox
)
from untitled import Ui_PasswordGender
import  sys
import  string  # py模块含有字符
import random

class MyPasswordGenerate(Ui_PasswordGender, QDialog, ):
    def __init__(self):
        super().__init__()

        self.setupUi(self)

        self.show()

        self.pushButton.clicked.connect(
            self.new_password
        )

    def new_password(self):
        site =self.lineEdit_site.text()
        if not site:
            QMessageBox.warning(self,'信息提示','请输入网站名')
            return

        words =[]
        if self.checkBox_upper.isChecked():
            words.append(string.ascii_uppercase * 2)
        # 因为以下默认生成的字符串个数,都是默认的10个,当只勾选一个格式,比如说只选数字,就达不到要求的20个,所以就*2
        if self.checkBox_lover.isChecked():
            words.append(string.ascii_lowercase * 2)

        if self.checkBox_number.isChecked():
            words.append(string.digits * 2)

        if self.checkBox_puc.isChecked():
            words.append(string.punctuation * 2)

        if not words:
            words = (
                string.digits  # 生成数字
                + string.ascii_uppercase  # 生成大写字母
                + string.ascii_lowercase  # 生成小写字母
                + string.punctuation      # 生成标点符号
            )
        else:
            words = "".join(words)

        words = random.sample(list(words), 20)  # list(words)在生成的字符串中,取20个字符
        password = ''.join(words)
        self.lineEdit_resilt.setText(password)   # 把密码写入lineEdit的框中

        with open('我的密码本.txt','a',encoding='utf-8') as f:
            f.write(f'{site}\t{password}\n')

        QMessageBox.information(
            self,'信息提示','密码生成成功'
        )


if __name__ == '__main__':
    app = QApplication(sys.argv)  # 启动应用程序

    myPasswordGenerate = MyPasswordGenerate() # MyPasswordGenerate类中已经有show()了,所以可以直接显示窗口

    sys.exit(app.exec())

ui_Python文件展示:

# Form implementation generated from reading ui file 'untitled.ui'
#
# Created by: PyQt6 UI code generator 6.4.2
#
# WARNING: Any manual changes made to this file will be lost when pyuic6 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt6 import QtCore, QtGui, QtWidgets


class Ui_PasswordGender(object):
    def setupUi(self, PasswordGender):
        PasswordGender.setObjectName("PasswordGender")
        PasswordGender.resize(578, 377)
        self.verticalLayout = QtWidgets.QVBoxLayout(PasswordGender)
        self.verticalLayout.setObjectName("verticalLayout")
        self.horizontalLayout = QtWidgets.QHBoxLayout()
        self.horizontalLayout.setObjectName("horizontalLayout")
        self.label = QtWidgets.QLabel(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.horizontalLayout.addWidget(self.label)
        self.lineEdit_site = QtWidgets.QLineEdit(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        font.setBold(True)
        self.lineEdit_site.setFont(font)
        self.lineEdit_site.setObjectName("lineEdit_site")
        self.horizontalLayout.addWidget(self.lineEdit_site)
        self.verticalLayout.addLayout(self.horizontalLayout)
        self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
        self.horizontalLayout_2.setObjectName("horizontalLayout_2")
        self.checkBox_upper = QtWidgets.QCheckBox(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.checkBox_upper.setFont(font)
        self.checkBox_upper.setObjectName("checkBox_upper")
        self.horizontalLayout_2.addWidget(self.checkBox_upper)
        self.checkBox_lover = QtWidgets.QCheckBox(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.checkBox_lover.setFont(font)
        self.checkBox_lover.setObjectName("checkBox_lover")
        self.horizontalLayout_2.addWidget(self.checkBox_lover)
        self.checkBox_number = QtWidgets.QCheckBox(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.checkBox_number.setFont(font)
        self.checkBox_number.setObjectName("checkBox_number")
        self.horizontalLayout_2.addWidget(self.checkBox_number)
        self.checkBox_puc = QtWidgets.QCheckBox(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        self.checkBox_puc.setFont(font)
        self.checkBox_puc.setObjectName("checkBox_puc")
        self.horizontalLayout_2.addWidget(self.checkBox_puc)
        self.verticalLayout.addLayout(self.horizontalLayout_2)
        self.pushButton = QtWidgets.QPushButton(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        font.setBold(True)
        self.pushButton.setFont(font)
        self.pushButton.setObjectName("pushButton")
        self.verticalLayout.addWidget(self.pushButton)
        self.lineEdit_resilt = QtWidgets.QLineEdit(parent=PasswordGender)
        font = QtGui.QFont()
        font.setPointSize(24)
        font.setBold(True)
        self.lineEdit_resilt.setFont(font)
        self.lineEdit_resilt.setObjectName("lineEdit_resilt")
        self.verticalLayout.addWidget(self.lineEdit_resilt)

        self.retranslateUi(PasswordGender)
        QtCore.QMetaObject.connectSlotsByName(PasswordGender)

    def retranslateUi(self, PasswordGender):
        _translate = QtCore.QCoreApplication.translate
        PasswordGender.setWindowTitle(_translate("PasswordGender", "密码生成小程序"))
        self.label.setText(_translate("PasswordGender", "请输入网站名称:"))
        self.checkBox_upper.setText(_translate("PasswordGender", "大写字母"))
        self.checkBox_lover.setText(_translate("PasswordGender", "小写字母"))
        self.checkBox_number.setText(_translate("PasswordGender", "数字"))
        self.checkBox_puc.setText(_translate("PasswordGender", "标点符号"))
        self.pushButton.setText(_translate("PasswordGender", "生成新密码"))

效果展示:

可以以选择生成格式,可多选,也可以都不选(即混合模式)

在这里插入图片描述

生成后并存成txt文件中(以追加的方式)

在这里插入图片描述

生成打包文件,还是先打开

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

打包语法之全部打包

 pyinstaller -F -w password_generate_main.py # password_generate_main.py是我运行的主程序py文件

在这里插入图片描述

打包后运行效果:

在这里插入图片描述

相关推荐

  1. secrets --- 生成管理密码安全随机数

    2024-04-03 11:58:05       39 阅读
  2. C语言实例_生成6位数随机密码(强迫症福音)

    2024-04-03 11:58:05       35 阅读
  3. 如何在Python生成随机密码

    2024-04-03 11:58:05       9 阅读
  4. pwgen 随机密码生成

    2024-04-03 11:58:05       34 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-03 11:58:05       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-03 11:58:05       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-03 11:58:05       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-03 11:58:05       20 阅读

热门阅读

  1. delegate(委托),Event(事件),Action,Func

    2024-04-03 11:58:05       14 阅读
  2. 第十四届省赛大学B组(C/C++) 冶炼金属

    2024-04-03 11:58:05       14 阅读
  3. Linux--文件、分区与挂载

    2024-04-03 11:58:05       10 阅读
  4. C语言标准库

    2024-04-03 11:58:05       16 阅读
  5. SpringMVC转发和重定向

    2024-04-03 11:58:05       14 阅读
  6. 【C++】编程规范之函数规则

    2024-04-03 11:58:05       17 阅读
  7. 深入理解WebSocket:实时双向通信的利器

    2024-04-03 11:58:05       13 阅读
  8. 【力扣】4. 寻找两个正序数组的中位数

    2024-04-03 11:58:05       14 阅读
  9. C语言求解最大公约数(欧几里得算法的应用)

    2024-04-03 11:58:05       14 阅读
  10. vue 父组件怎么获取子组件里面的data数据

    2024-04-03 11:58:05       16 阅读