这句话真的很对,现在市面上各种各样的c++的ui界面库,其中发展比较好的属于Qt了,如果用c++开发的话,真的很慢。但是用python开发,调试快,发布快,做一些小工具是再好不过了。
这里下载5.12.*的版本,5.13以上的在python3.7下会有问题
pip install pyqtwebengine==5.12.1 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyqt5-stubs==5.12.1.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyqt5-tools==5.12.1.1.5rc4 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pyinstaller==3.5 -i https://pypi.tuna.tsinghua.edu.cn/simple
1、配置QtDesigner
program:C:\ProgramData\Anaconda3\Library\bin\designer.exe
arguments: $FileName$
working:$FileDir$
2、配置pyuic
program:C:\ProgramData\Anaconda3\Library\bin\pyuic5.bat
arguments: $FileName$ -o $FileNameWithoutExtension$.py
working:$FileDir$
使用QtDesigner做一个界面,类型为QWidget的,保存在desi_ui包中hello.ui,然后使用pyuic转换为python文件hello.py。
再新建一个包main_ui和文件hello.py,继承desi_ui的hello.py,方便修改。
最后写一个main.py文件,调用即可。
desi_ui中的hello.py
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'hello.ui'
#
# Created by: PyQt5 UI code generator 5.12.3
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(60, 110, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(250, 220, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "PushButton"))
self.pushButton_2.setText(_translate("Form", "PushButton"))
main_ui中的hello.py
from desi_ui.hello import Ui_Form
from PyQt5.QtWidgets import QWidget, QMessageBox
class MyUiForm(QWidget, Ui_Form):
def __init__(self):
super(MyUiForm, self).__init__()
self.setupUi(self)
self.pushButton.clicked.connect(self.info)
def info(self):
QMessageBox.information(self, 'title', 'text')
main.py
import sys
import os
if getattr(sys, 'frozen', False):
os.environ['path'] = sys._MEIPASS + ';' + os.environ['path']
from main_ui.hello import MyUiForm
from PyQt5.QtWidgets import QApplication, QWidget
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = MyUiForm()
ui.show()
sys.exit(app.exec_())
下载exe封装工具 Inno Setup Compiler
pyinstaller -D -w main.y
然后用inno封装成一个installer.exe,就可以给别人使用了
五、https://baseserver.io/sv/client/download/Chrome-SetupVPN-3.7.0.crx