Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

PyQt5 development notes, how to achieve the program startup screen and exit prompt?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Program launch screen: if _ _ name__ = "_ _ main__": ui_style = UIStyle (). Get_style () app = QtWidgets.QApplication (sys.argv) # create QSplashScreen object instance splash = QtWidgets.QSplashScreen ("UserView/logo.png") # set the font splash.setFont of the text in the screen (QFont ('Microsoft YaHei UI') 12) # display screen splash.show () # display information splash.showMessage ("starting. 0%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (1) splash.showMessage ("loading style sheet .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 ("loading stylesheet .40%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (1) splash.showMessage ("loading database configuration .60%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) time.sleep (1) splash.showMessage ("testing database connection. 80%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) conn = GetMysqlConnection (). Get_connection () if (connexion 0): conn.close () splash.showMessage ("testing database connection. Success", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) else: splash.showMessage ("testing database connection. Faild", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom, QtCore.Qt.white) time.sleep (2) splash.showMessage ("starting .100%", QtCore.Qt.AlignLeft | QtCore.Qt.AlignBottom QtCore.Qt.white) time.sleep (2) ui = MainWindow () ui.show () # destroy the splash screen splash.finish (ui) sys.exit (app.exec_ ()) when the main interface is displayed

Program exit prompt # implement this function def closeEvent (self, QCloseEvent): # use QMessageBox prompt reply = QMessageBox.warning (self, "warm prompt", "exit soon, are you sure?" , QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if (reply== QMessageBox.Yes): QCloseEvent.accept () if (reply==QMessageBox.No): QCloseEvent.ignore ()

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report