0

I am working on a project, it is almost complete, i am working on it's gui. i want to show a transparent image for 5 sec while starting the program in python

Community
  • 1
  • 1

1 Answers1

2

What you need is a splash screen, thats what the transparent image is called,

You can use pyQt to do this, it can be done via the code

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)

    splash_pix = QtGui.QPixmap('img_name.jpg')
    splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)
    splash.show()

    def login():
        splash.close()
        if Login().exec_() == QtGui.QDialog.Accepted:
            global window
            window = Main_Window()
            window.show()
        else:
            app.quit()

    show_time = 5000 # time in seconds * 1000 (milliseconds), hence 5 seconds = 5000 ms
    QtCore.QTimer.singleShot(show_time, login)

    sys.exit(app.exec_())

The code is originally by Splash screen in pyqt

Could not flag it as duplicate due to lack of accepted answer, please accept this so this can be done for the future

In terms of functionality it works, i have used it before

Imtinan Azhar
  • 1,725
  • 10
  • 26
  • I am new to this PyQt module can you pls provide me the code for tkinter module and also the import lines are not present, – Pushpender Singh Sep 26 '19 at 12:46
  • I added these three lines `from PyQt5.QtGui import *` `from PyQt5.QtCore import *` `import sys` but got error, this is error: `NameError: name 'QtGui' is not defined` – Pushpender Singh Sep 26 '19 at 12:48