Reputation: 109
I'm trying to add an splash screen to my program, coded in python 2.7 and using pyqt4 libraries. My main file is:
#!/usr/bin/env python
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from logindialog import LoginDialog
from mainwindow import MainWindow
import time
import sys
if __name__ == "__main__":
try:
app = QApplication(sys.argv)
mw = MainWindow()
# Create and display the splash screen
splash_pix = QPixmap('images/sherlock_splash.png')
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
splash.setMask(splash_pix.mask())
# adding progress bar
progressBar = QProgressBar(splash)
# adding message
splash.showMessage('Discovering Nodes...', Qt.AlignRight | Qt.AlignBottom, Qt.darkRed)
splash.show()
app.processEvents()
for i in range(0, 100):
progressBar.setValue(i)
# Simulate something that takes time
time.sleep(0.1)
splash.close()
# Show main window
mw.show()
app.exec_()
except Exception:
sys.exit(1)
sys.exit(0)
I've coded it using Pycharm IDE. If I run it using pycharm RUN functionality the splash screen is shown up properly, however if I run it in linux command line (./main.py) it does not show up splash screen when I start my application.
Anybody could help me?
Thanks a lot!
UPDATE & FIX
...
# Create and display the splash screen
image_path = os.path.dirname(os.path.realpath(__file__))
splash_pix = QPixmap('/'.join([image_path, 'images/sherlock_splash.png']))
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
...
Thanks!
Upvotes: 1
Views: 4727
Reputation: 9865
Check your project structure and be sure if the relative path to your .png
file is correct
'images/sherlock_splash.png'
when running from command line.
Also add following checking
if splash_pix is not None:
...
Upvotes: 2