Python代码使用PyQt5制作界面并封装 | 您所在的位置:网站首页 › python编写界面生成exe › Python代码使用PyQt5制作界面并封装 |
续: https://blog.csdn.net/yulinxx/article/details/93344163 若要对此程序进行封装,加个界面,然后制作成EXE, 使用PyQt5制作界面,PyInstaller 进行封装成EXE可参考: Python制作小软件——1. 安装并使用PyQt5进行界面设计https://blog.csdn.net/weixin_41929524/article/details/81456308 Python制作小软件——2. 实现界面中的退出功能https://blog.csdn.net/weixin_41929524/article/details/81460203 Python制作小软件——3. 利用PyQt5实现界面中的功能https://blog.csdn.net/weixin_41929524/article/details/81475935 Python制作小软件——4. 利用PyInstaller打包成exe文件https://blog.csdn.net/weixin_41929524/article/details/81484806 归纳: pip国内源设置方法 https://blog.csdn.net/weixin_41712059/article/details/86704492 安装PyQt5 ·pip install PyQt5 Qt随意新建一个QWidget的工程,只要能有设计界面就可以, 制作了 .ui 界面后,执行: pyuic5 -o d:\ui.py D:\xx\Documents\QtProj\UIForPython\mainwindow.ui 输出到本地 d:\ui.py 最终打包: 安装打包工具:pip install PyInstaller 打包主程序pyinstaller -F -w main.py 它会自动添加依赖,最终生成一个exe文件,体积较大 遇到的坑: 关于pyqt4关闭窗口报错的解决方法 - 半日晴天半日雨的专栏 - CSDN博客 https://blog.csdn.net/jackhuang2015/article/details/55056229 关闭窗口,程序崩溃,直接加上如下代码,程序会自动调用: def closeEvent(self, event): quit() 界面设置文字未及时刷新,加上如下第三行代码即可: self.textEditStatus.setStyleSheet('color:green') self.textEditStatus.setText('安装中,请稍候...') QApplication.processEvents() # 界面刷新 PyQt 如果异常未处理,抛入到事件循环,则无错误提示崩溃的解决方法 - hidxl的专栏 - CSDN博客 https://blog.csdn.net/hidxl/article/details/49800353在PyQt5中,如果在Python 代码中抛出了异常,没有进行捕获,异常只要进入事件循环,程序就崩溃,而没有任何提示,给程序调试带来不少麻烦,通过在程序运行前加入以下代码,则能避免程序崩溃. import cgitb cgitb.enable( format = ‘text’) Qt学习 重写closeEvent退出对话框 https://blog.csdn.net/amusi1994/article/details/69934313部分代码: 设置按钮与事件的关联: def initUI(self): self.lineEditPassword.setEchoMode(QtWidgets.QLineEdit.Password)#密码模式 self.pushBtnDebBrowse.clicked.connect(self.browseDebFolder) self.pushBtnExit.clicked.connect(self.exit)槽函数: def browseDebFolder(self): filename, filetype =QFileDialog.getOpenFileName(self, "选取文件", ".", "All Files(*);;Text Files(*.deb)") if filename: print(filename, '\t', filetype) pos = filename.rfind('/') str_file = filename[pos+1 : ] self.lineEditDebSrcPath.setText(filename) self.lineEditDebDstPath.setText('/home/' + str_file) def exit(self): print("Exit") self.close() sys.exit(0) |
CopyRight 2018-2019 实验室设备网 版权所有 |