Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

python - Splash screen in pyqt

I want to modify my code to add the splash screen before login dialog is shown(about 2 seconds) .i tried something(changed into comment )but not working .please show me how to modify my code.

  import sys
  from time import *
  from PyQt4 import QtGui,QtCore
  from loginD import *
  from mainwindow import Ui_MainWindow

 class Login(QtGui.QDialog):
 #A dialog with username and password lineedit
  def __init__(self,parent=None):
    QtGui.QDialog.__init__(self,parent)
    self.ui=Ui_LoginD()
    self.ui.setupUi(self)
    self.ui.PasswordLE.setEchoMode(QtGui.QLineEdit.Password)
    QtCore.QObject.connect(self.ui.LoginPB,QtCore.SIGNAL('clicked()'),
                           self.HandleLogin)
def HandleLogin(self):
    if  self.ui.PasswordLE.text()=="pass":
        self.accept()

    else:
        QtGui.QMessageBox.warning(
            self,'Error;','bad')

class Main_Window(QtGui.QMainWindow,):
#main window ui 
 def __init__(self,parent=None):
    QtGui.QWidget.__init__(self,parent)
    self.ui=Ui_MainWindow()
    self.ui.setupUi(self)



if __name__=='__main__':
 app=QtGui.QApplication(sys.argv)
 #splash_pix=QtGui.QPixmap('logo and typeface blue.jpg')
 #splash=QtGui.QSplashScreen(splash_pix,QtCore.Qt.WindowStaysOnTopHint)
 #splash.show()
 # app.processEvents()
#time.sleep(2)
if Login().exec_()==QtGui.QDialog.Accepted:
    window=Main_Window()
    window.show()
    sys.exit(app.exec_())
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use a timer to start the login procedure:

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)

    splash_pix = QtGui.QPixmap('logo and typeface blue.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()

    QtCore.QTimer.singleShot(2000, login)

    sys.exit(app.exec_())

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...