PyQt5 simple widget production steps:

After learning python for several months, I suddenly want to make some of my own tools. I remember that when I used to write GUI of C + + with QT, I remember that I can write GUI with pyqt, and I have been learning for a week. I've read all the basic things. It's almost like QT! But pyqt5's Chinese materials are poor! If you want to learn again, you can refer to my gadget making process!

Look at the code first

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.lineEdit = QLineEdit()
        self.button = QPushButton("start")
        self.text = QTextEdit()
        #Signal in slot
        #Layout nesting
        wlayout = QVBoxLayout(self) #Global layout
        hlayout = QHBoxLayout() #Local layout
        vlayout = QVBoxLayout() #Local layout


        wlayout.addLayout(hlayout) #Add partial layout to global layout
        #Add title
        self.setWindowTitle("URL Grab")
        #Add Icon

    #Slot function
    def getstr(self):
        url = self.lineEdit.text()
        rep = requests.get(url)
        rep.encoding = 'utf-8'
        html = rep.text
        #Add the source code to textEdit
        #setText() this function cannot be implemented

if __name__ =="__main__":
    app = QApplication(sys.argv)
    demo = MyTest()

Download pyinstaller library, pip install pyinstaller
If you install Python 3.6, you need to download the latest development version from github

pyinstaller.exe -w -F –icon="1.ico"

-w is no black console
-F file path
– ico add program icon

After packing:

In dist, there are the tools we finally generated:

If you want to download good-looking icons, you can recommend a good website:

ps: if you find any mistakes, please correct them! No sprays!

Tags: Python Qt encoding pip

Posted on Sun, 31 May 2020 09:41:22 -0400 by brash