pyqt6开发的第一个程序

pyqt6的开发环境如何配置看如下教程

pyqt6开发环境的配置

用qtdesigner设计界面,并用命令行把界面转换成py语言。

查看自己的虚拟开发环境

conda env list



qtdesigner的目录如下:



界面最终效果



把界面转换成py脚本

pyuic6 myui.ui -o myui.py

编写代码部分

写代码调用界面,按钮响应函数如何写,界面和代码的互动。

from PyQt6.QtWidgets import (    QApplication, QDialog, QMessageBox)from myui import Ui_Dialogimport sysimport stringimport osclass MyApp(Ui_Dialog, QDialog):    def __init__(self):        super().__init__()        self.setupUi(self)        self.show()        self.pushButton_start.clicked.connect(self.start)        self.pushButton_stop.clicked.connect(self.start)        self.pushButton_reload.clicked.connect(self.start)        self.pushButton_taskkill.clicked.connect(self.taskkill)    def start(self):        self.lineEdit.setText("start")        os.system("start nginx")        QMessageBox.information(            self, "标题", "内容"        )    def stop(self):        self.lineEdit.setText("stop")        os.system("nginx -s stop")        QMessageBox.information(            self, "标题", "内容"        )    def reload(self):        self.lineEdit.setText("reload")        os.system("nginx -s reload")        QMessageBox.information(            self, "标题", "内容"        )    def taskkill(self):        self.lineEdit.setText("杀掉所有nginx进程")        #oa.system("taskkill /f /t /im nginx.exe")        # QMessageBox.information(        #     self, "标题", "内容"        # )if __name__ == "__main__":    print(sys.argv)    app = QApplication(sys.argv)    myapp = MyApp()    sys.exit(app.exec())

生成可执行程序


pyinstaller -F -w runme.py


工程目录


最终生成的exe


发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章