安装配置了pyuic和pyrcc后再进行下面操作
1、打开: 位置(我的):C:\Users\AppData\Roaming\Python\Python35\site-packages\pyqt5_tools\designer.exe
2、设计: 新建MainWindow通过拖拽,设计想要的界面,保存为x.ui文件(名字x随便起)
3、编译: 自动编译:用pycharm找到保存的x.ui文件,右键选择External Tool》》PyUIC就会生成x.py文件
代码编译:pyuic5 C:\Users\gucunlin\test\x.ui -o C:\Users\gucunlin\test\x.py
----------------------------------------以上工作是为了不写代码就生成有界面的py文件如果你嫌麻烦,直接手写x.py文件同样可以---------------------------------------------------------------
4、写逻辑: 包括文本框的内容读取和赋值以及按钮事件等
5、生成exe: 先安装pyinstaller(安装参考https://blog.csdn.net/lqzdreamer/article/details/77917493)再在目标文件处打开cmd运行如下命令,即可得到x.exe文件。
pyinstaller -F --icon=my.ico test.py
参数:
–icon=图标路径
-F 打包成一个exe文件
-w 使用窗口,无控制台
-c 使用控制台,无窗口
-D 创建一个目录,里面包含exe以及其他一些依赖性文件
实例代码:
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'insertDB.ui'
#
# Created by: PyQt5 UI code generator 5.11.3
#
# WARNING! All changes made in this file will be lost!
import os
import sys
from beifen import MyInsertOracle from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(682, 551)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.summaryPath = QtWidgets.QTextEdit(self.centralwidget)
self.summaryPath.setGeometry(QtCore.QRect(150, 40, 431, 31))
self.summaryPath.setObjectName("summaryPath")
self.activityPath = QtWidgets.QTextEdit(self.centralwidget)
self.activityPath.setGeometry(QtCore.QRect(150, 80, 431, 31))
self.activityPath.setObjectName("activityPath")
self.logs = QtWidgets.QTextBrowser(self.centralwidget)
self.logs.setGeometry(QtCore.QRect(150, 220, 431, 261))
self.logs.setObjectName("logs")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(280, 140, 101, 41))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(60, 40, 71, 21))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(60, 90, 71, 16))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(60, 340, 31, 16))
self.label_3.setObjectName("label_3")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 682, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate('MainWindow', 'MainWindow'))
self.pushButton.setText(_translate("MainWindow", "开始插入"))
self.label.setText(_translate("MainWindow", "路径summary"))
self.label_2.setText(_translate("MainWindow", "路径activity"))
self.label_3.setText(_translate("MainWindow", "log"))
self.pushButton.clicked.connect(self.insertOracle)
# self.connect(self.pushButton, QtCore.SIGNAL("clicked()"),self.showbox)
# self.pushButton = Button(self.init_window_name, text="字符串转MD5", bg="lightblue", width=10,command=self.str_trans_to_md5) # 调用内部方法 加()为直接调用 def insertOracle(self):
path_person=self.summaryPath.toPlainText()
path_detail=self.activityPath.toPlainText()
self.logs.append('summery:'+path_person)
self.logs.append('activity:'+path_detail) if __name__ == '__main__': app = QApplication(sys.argv)
mainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())