Python3 GUI开发(PyQt5)安装和配置:
- 下载安装好Miniconda3, 并且安装好jupyter 注意:最好关闭360杀毒软件或者把cmd加入信任,否则运行activate会有问题。
- 进入工作区,下载安装PyQt5,需要用镜像,不然下载网络非常不给力。
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyQt5pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyQt5-tools
- 启动运行Qt designer:
E:\Miniconda3\envs\SkyPy3\Lib\site-packages\pyqt5-tools>designer.exe
- 拖下窗口和按钮
- 点File->Save
- 此时保存的是.ui文件,需要转换成.py文件,运行以下命令:
python -m PyQt5.uic.pyuic -o E:\PythonWorkSpace\PyQT\frist.py E:\PythonWorkSpace\PyQT\test.ui
- 发现生成了first.py文件
- 打开first.py文件,并复制到jupyter
import sysfrom PyQt5 import QtCore, QtGui, QtWidgetsclass Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(800, 600) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.textBrowser = QtWidgets.QTextBrowser(self.centralwidget) self.textBrowser.setGeometry(QtCore.QRect(30, 20, 256, 192)) self.textBrowser.setObjectName("textBrowser") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(380, 40, 75, 23)) self.pushButton.setObjectName("pushButton") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 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", "Click"))if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_())
- 启动程序
窗口出现,配置完成!