pyqt5 使用拖拽生成图形界面并打包成exe
安装
pip install PyQt5
PyQt Designer在pyqt5-tools 里面
pip install pyqt5-tools
界面ui设计
打开py目录\Lib\site-packages\qt5_applications\Qt\bin\designer.exe进行ui拖拽设计并生成xx.ui文件
使用以下命令生成模板代码
pyuic5 -o xx.py xx.ui
逻辑对接视图
# -*- coding: utf-8 -*-
import post
import name
import sys
import lib
import os
from PyQt5.QtWidgets import QApplication, QMainWindow
def click_success():
# 获取input框的值
input = ui.lineEdit.text()
# 获取radio选中的值
bt = ui.radioButton.isChecked()
bt2 = ui.radioButton_2.isChecked()
_type = 1
if bt2:
_type = 2
suc, res = post.getKRByQuery(input, _type)
_content = ''
if suc:
_content += '获取成功\n'
if res:
path = lib.product_csv(input, res)
os.startfile(path)
_content += '结果已经输出到文件:' + path
else:
_content += '结果为空'
else:
_content += '获取失败\n'
_content += '原因:' + res['message']
# 响应结果
ui.textEdit.setText(_content)
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = name.Ui_MainWindow()
ui.setupUi(MainWindow)
# 绑定点击事件
ui.pushButton.clicked.connect(click_success)
MainWindow.show()
sys.exit(app.exec_())
打包成exe
pip install pyinstaller
pyinstaller -F -w xx.py