pyqt中的启动画面 [英] Splash screen in pyqt
本文介绍了pyqt中的启动画面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想修改我的代码以在显示登录对话框之前添加启动画面(大约 2 秒).我尝试了一些东西(改成评论)但不起作用.请告诉我如何修改我的代码.
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_())
推荐答案
使用计时器启动登录程序:
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_())
这篇关于pyqt中的启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文