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.label.setText("website") self.lineEdit = QLineEdit() #self.lineEdit.setText("http://www.baidu.com") self.button = QPushButton("start") self.text = QTextEdit() #Signal in slot self.button.clicked.connect(self.getstr) #Layout nesting wlayout = QVBoxLayout(self) #Global layout hlayout = QHBoxLayout() #Local layout vlayout = QVBoxLayout() #Local layout hlayout.addWidget(self.label) hlayout.addWidget(self.lineEdit) hlayout.addWidget(self.button) vlayout.addWidget(self.text) wlayout.addLayout(hlayout) #Add partial layout to global layout wlayout.addLayout(vlayout) #Add title self.setWindowTitle("URL Grab") #Add Icon self.setWindowIcon(QIcon('1.ico')) #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 self.text.setPlainText(html) if __name__ =="__main__": app = QApplication(sys.argv) demo = MyTest() demo.show() sys.exit(app.exec())
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" mytest.py
-w is no black console
-F file path
– ico add program icon
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!