python – pyqt中的启动画面
作者:互联网
我想修改我的代码以在显示登录对话框之前添加启动画面(大约2秒)
.i尝试了一些东西(改成评论)但没有工作.请告诉我如何修改我的代码.
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_())
解决方法:
使用计时器启动登录过程:
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_())
标签:python,pyqt,splash-screen 来源: https://codeday.me/bug/20190929/1833328.html