1
我試圖在我的程序中添加啓動畫面,使用python 2.7編碼並使用pyqt4庫。我的主要文件是:Qt啓動畫面沒有在Python中顯示
#!/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)
我已經使用Pycharm IDE編碼它。如果我使用pycharm RUN功能運行它,啓動屏幕會正常顯示,但是如果我在Linux命令行(./main.py)中運行它,它在啓動我的應用程序時不顯示啓動屏幕。
有人可以幫助我嗎?
非常感謝!
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)
...
謝謝!
我使用的icewm ... – dpatino