Python实现卡密生成器,轻松生成卡密

最近我在做一个基于 openCv2 的脚本,顺手写了一个卡密生成器,也给自己保存一下代码。

代码部分

import threading

from PyQt5 import QtWidgets, uic
from PyQt5.QtWidgets import QMessageBox
import random as random_utils


class MyWindow(QtWidgets.QMainWindow):
    def __init__(self):
        super().__init__()
        # 从文件中加载UI定义
        uic.loadUi('Cami.ui', self)
        # 获取按钮对象
        self.btn = self.findChild(QtWidgets.QPushButton, 'But_LeftOne')
        self.btn2 = self.findChild(QtWidgets.QPushButton, 'But_LeftTwo')
        self.btn3 = self.findChild(QtWidgets.QPushButton, 'But_LeftThree')
        # 为按钮连接槽函数
        self.btn.clicked.connect(self.onCamiClick)
        self.btn2.clicked.connect(self.onDIYClick)
        self.btn3.clicked.connect(self.onshows)

        # self.edt_password.returnPressed.connect(self.onSignIn)
        # self.output = self.findChild(QtWidgets.QLabel, 'edt_cami')

    def onDIYClick(self):
        t2 = threading.Thread(target=self.onDIY)
        t2.start()
        # t3 = threading.Thread(target=self.judgment)
        # t3.start()

    def onDIY(self):
        # 获取编辑框对象
        output = self.findChild(QtWidgets.QLineEdit, 'edt_cami')
        # 获取编辑框对象
        diy = self.findChild(QtWidgets.QLineEdit, 'edt_length').text()
        try:
            diyint = int(diy)
        except ValueError:
            output = self.findChild(QtWidgets.QLineEdit, 'edt_cami')
            output.setText("注意,在长度框中只能输入数字!")
            return

        outcome = dislocate(diyint)
        # 在编辑框中输出随机字符串
        output.setText(outcome)

    def onCamiClick(self):
        # 创建一个线程
        t1 = threading.Thread(target=self.output_outcome)
        # 启动线程
        t1.start()

    def output_outcome(self):
        outcome = dislocate(30)
        # 获取编辑框对象
        output = self.findChild(QtWidgets.QLineEdit, 'edt_cami')
        # 在编辑框中输出随机字符串
        output.setText(outcome)

    def onshows(self):
        msg_box = QMessageBox()
        msg_box.setWindowTitle('说明')
        msg_box.setText('2.自定义的长度尽量大于30否则有可能重复.\n'
                        '3.目前已知最大可创建的长度为32767个字符.')
        result = msg_box.exec_()




def dislocate(length):
    content = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    outcome = ''
    for i in range(length):
        outcome += random_utils.choice(content)

    return outcome





if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    window = MyWindow()
    window.show()
    app.exec_()

接下来是下载连接,因为比较小就用某云盘了,知道的它下载一直很慢,其实也不算小Python打包出来的东西还是挺大的,压缩包里有一个ui文件不要删,那个是动态加载进的Qt文件把它和主程序放在同一个目录下就可以打开了

链接:https://pan.baidu.com/s/14bNTgB-Ws7ywCYwhBQw6HA 
提取码:1234

物联沃分享整理
物联沃-IOTWORD物联网 » Python实现卡密生成器,轻松生成卡密

发表评论