PyQt5开发小记,如何实现程序启动画面和退出提示?
程序启动画面:
if __name__ == "__main__":
ui_style = UIStyle().get_style()
app = QtWidgets.QApplication(sys.argv)
# 创建QSplashScreen对象实例
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("UserView/logo.png"))
# 设置画面中的文字的字体
splash.setFont(QFont('Microsoft YaHei UI', 12))
# 显示画面
splash.show()
# 显示信息
splash.showMessage("启动中... 0%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
time.sleep(1)
splash.showMessage("正在加载样式表...20%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
if(ui_style=='dark'):
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
time.sleep(1)
splash.showMessage("正在加载样式表...40%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
time.sleep(1)
splash.showMessage("正在加载数据库配置...60%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
time.sleep(1)
splash.showMessage("正在测试数据库连接...80%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
conn = GetMySQLConnection().get_connection()
if(conn!=0):
conn.close()
splash.showMessage("正在测试数据库连接...Success", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
else:
splash.showMessage("正在测试数据库连接...faild", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
time.sleep(2)
splash.showMessage("启动中...100%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white)
time.sleep(2)
ui = MainWindow()
ui.show()
# 当主界面显示后销毁启动画面
splash.finish(ui)
sys.exit(app.exec_())
创新互联专注于合作企业网站建设,响应式网站设计,商城网站建设。合作网站建设公司,为合作等地区提供建站服务。全流程按需策划,专业设计,全程项目跟踪,创新互联专业和态度为您提供的服务
程序退出提示
# 实现这个函数
def closeEvent(self, QCloseEvent):
# 使用QMessageBox提示
reply = QMessageBox.warning(self, "温馨提示", "即将退出, 确定?", QMessageBox.Yes|QMessageBox.No, QMessageBox.No)
if(reply == QMessageBox.Yes):
QCloseEvent.accept()
if(reply==QMessageBox.No):
QCloseEvent.ignore()
文章标题:PyQt5开发小记,如何实现程序启动画面和退出提示?
路径分享:http://ybzwz.com/article/jhiicp.html