• PyQt5-GUI生成随机生成小工具


    自己修改了代码:实现了自动生成SSN,手机号和姓名的功能

    import sys
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    import requests
    from generator import random_ssn,random_phone_number,random_name
    
    class MyTest(QWidget):
    
        def __init__(self, parent=None):
            super(MyTest, self).__init__(parent)
    
            self.label = QLabel(self)
            # self.label.setText("生成SSN")
            # self.lineEdit = QLineEdit()
            #self.lineEdit.setText("http://www.baidu.com")
            self.button_ssn = self.models("SSN",self.random_ssn)
            self.button_pnumber = self.models("手机号",self.random_number)
            self.button_name = self.models("姓名",self.random_name)
            self.text = QTextEdit()
            #信号于槽
    
            #布局嵌套
            wlayout = QVBoxLayout(self) #全局布局
            hlayout = QHBoxLayout() #局部布局
            vlayout = QVBoxLayout() #局部布局
    
            hlayout.addWidget(self.label)
            # hlayout.addWidget(self.lineEdit)
            hlayout.addWidget(self.button_ssn,stretch=10)
            hlayout.addWidget(self.button_pnumber)
            hlayout.addWidget(self.button_name)
            vlayout.addWidget(self.text)
    
            wlayout.addLayout(hlayout) #将局部布局加到全局布局中
            wlayout.addLayout(vlayout)
            #添加标题
            self.setWindowTitle("生成SSN小工具")
            #添加图标
            self.setWindowIcon(QIcon(r'F:GitHubBuy123061.png'))
    
        def models(self,name,func):
            self.button = QPushButton(name)
            self.button.clicked.connect(func)
            return self.button
    
    
        #槽函数
        def random_ssn(self):
            # url = self.lineEdit.text()
            # rep = requests.get(url)
            # rep.encoding = 'utf-8'
            # html = rep.text
            for i in range(5):
                ssn = random_ssn()
            #将抓取的网页源码加入到textEdit中
            #setText()这个函数不能实现
                self.text.setPlainText(ssn)
    
        def random_number(self):
            phoneNumber = random_phone_number()
            self.text.setPlainText(phoneNumber)
    
        def random_name(self):
            name = random_name()
            self.text.setPlainText(name)
    
    
    if __name__ =="__main__":
        app = QApplication(sys.argv)
        demo = MyTest()
        demo.show()
        sys.exit(app.exec())

    网上copy他人代码,这里借鉴一下:

    import sys
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
    from PyQt5.QtCore import *
    import requests
    
    class MyTest(QWidget):
    
        def __init__(self, parent=None):
            super(MyTest, self).__init__(parent)
    
            self.label = QLabel(self)
            self.label.setText("网址")
            self.lineEdit = QLineEdit()
            #self.lineEdit.setText("http://www.baidu.com")
            self.button = QPushButton("开始")
            self.text = QTextEdit()
            #信号于槽
            self.button.clicked.connect(self.getstr)
            #布局嵌套
            wlayout = QVBoxLayout(self) #全局布局
            hlayout = QHBoxLayout() #局部布局
            vlayout = QVBoxLayout() #局部布局
    
            hlayout.addWidget(self.label)
            hlayout.addWidget(self.lineEdit)
            hlayout.addWidget(self.button)
            vlayout.addWidget(self.text)
    
            wlayout.addLayout(hlayout) #将局部布局加到全局布局中
            wlayout.addLayout(vlayout)
            #添加标题
            self.setWindowTitle("URL抓取")
            #添加图标
            self.setWindowIcon(QIcon('1.ico'))
    
        #槽函数
        def getstr(self):
            url = self.lineEdit.text()
            rep = requests.get(url)
            rep.encoding = 'utf-8'
            html = rep.text
            #将抓取的网页源码加入到textEdit中
            #setText()这个函数不能实现
            self.text.setPlainText(html)
    
    
    
    if __name__ =="__main__":
        app = QApplication(sys.argv)
        demo = MyTest()
        demo.show()
        sys.exit(app.exec())

    打包 --- pyinstaller.exe -w -F  mytest.py

  • 相关阅读:
    提高优化PHP代码质量的9个技巧
    360打破欧美垄断勇夺黑客攻防大赛“世界冠军”
    php中ckeditor的配置方法
    vue 动态生成 el-checkbox-group 遇到的v-model绑定问题及解决方法
    在vue-cli中,使用 sass-resources-loader 实现全局变量、方法注入
    wp rest api 授权方法步骤(使用JWT Authentication插件)
    react redux dva 多次循环异步取数据的问题解决
    jquery.validate.js在IE8下报错不运行
    ichart.js绘制虚线 ,平均分虚线
    rgb转16进制 简单实现
  • 原文地址:https://www.cnblogs.com/nieliangcai/p/10730622.html
Copyright © 2020-2023  润新知