0

This is my main_script.py I want to show a window(splash) for 2 seconds & then open the main window. The splash window shows up & also waits 2 seconds then open the main window. But, the contents of the splash window are not loading.

I am struggling to understand how to manage the classes.

import time
from PyQt5 import QtCore, QtWidgets, uic
from MainWindow import Ui_MainWindow
from SplashWindow import Ui_SplashWindow

class SplashWindow(QtWidgets.QMainWindow, Ui_SplashWindow):
    def __init__(self, *args, **kwargs):
        super(SplashWindow, self).__init__(*args, **kwargs)
        self.setWindowFlags(QtCore.Qt.CustomizeWindowHint) # hide window titlebar
        self.setupUi(self)       

class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, *args, **kwargs):
        super(MainWindow, self).__init__(*args, **kwargs)
        self.setupUi(self)
        self.showSplash()

    def showSplash(self):
        splash = SplashWindow()
        splash.show()
        time.sleep(2)
        splash.hide()

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    main = MainWindow()
    main.show()
    sys.exit(app.exec_())```
RukshanJS
  • 791
  • 1
  • 7
  • 20
  • 1
    1) change `splash` to `self.splash`, 2) change `time.sleep(2) splash.hide()` to `QtCore.QTimer.singleShot(2 * 1000, self.splash.hide)` – eyllanesc Mar 22 '20 at 15:28
  • @eyllanesc thank you so much. That did the trick! Although I had to call the splash window first, then the main window. – RukshanJS Mar 22 '20 at 15:44

0 Answers0