主窗口之前的PyQt5启动屏幕

时间:2020-06-21 20:21:36

标签: python pyqt5

我正在尝试创建一个初始屏幕,该屏幕显示5秒钟,然后再显示主屏幕。但是,我希望初始屏幕与主窗口是同一窗口,而中间是不同的图像。

我看过How to change UI in same window using PyQt5?,但仍然无法正常工作...

我也尝试使用QSplashScreen类,但无法使其正常工作。如有任何混淆,请随时发表评论,我会澄清。

这是我的代码脚本:

# importing libraries 
from PyQt5.QtWidgets import * 
from PyQt5.QtGui import * 
from PyQt5 import QtCore, QtGui 
from PyQt5.QtCore import * 
import sys   
 
  
class Window(QMainWindow): 
    def __init__(self): 
        super().__init__() 
  
        self.setStyleSheet("background-color: black;")
        self.setWindowTitle("key") 
        self.setGeometry(100, 100, 350, 500) 
        self.UiComponents() 
        self.show() 
  

    def UiComponents(self): 
        lockButton = QPushButton(self) 
        lockButton.setGeometry(60, 200, 100, 70) 
        lockButton.setStyleSheet("border-radius : 10; border : 1px solid white; background-color : #3A3535") 
        lockButton.setIcon(QIcon('lock.png')) 
        size = QSize(40, 40) 
        lockButton.setIconSize(size)
        lockButton.clicked.connect(self.clickme) 
        

    def clickme(self): 
        print("pressed") 
  

App = QApplication(sys.argv) 
window = Window() 
sys.exit(App.exec()) 

1 个答案:

答案 0 :(得分:0)

尝试一下:

const logo = (props) => {
let logoClass = 'my-2 mr-4 ' + classes.Logo;
  return (
    <div className={logoClass}>
      <a href="/">
        <img src={logoimg} />
        <p>Resume Builder</p>
      </a>
    </div>
  );
};

enter image description here


仅加载图像,然后加载窗口。可以在同一窗口(只有纯黑屏幕)上加载图像,然后再加载主窗口吗?

from PyQt5.QtWidgets import * 
from PyQt5.QtGui import * 
from PyQt5 import QtCore, QtGui 
from PyQt5.QtCore import * 
import sys   
 
  
class Window(QMainWindow): 
    def __init__(self): 
        super().__init__() 
  
        self.setStyleSheet("background-color: black;")
        self.setWindowTitle("key") 
#        self.setGeometry(100, 100, 350, 500) 
        self.resize(350, 500) 
        
        self.UiComponents() 
        self.show() 
  

    def UiComponents(self): 
        lockButton = QPushButton(self) 
        lockButton.setGeometry(60, 200, 100, 70) 
        lockButton.setStyleSheet("border-radius : 10; border : 1px solid white; background-color : #3A3535") 
        lockButton.setIcon(QIcon('im.png'))              # ! 'lock.png'
        size = QSize(40, 40) 
        lockButton.setIconSize(size)
        lockButton.clicked.connect(self.clickme) 
        

    def clickme(self): 
        print("pressed") 
  

App = QApplication(sys.argv) 

# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
import time
splash = QSplashScreen()
splash.setPixmap(QPixmap('images/splash_.jpg').scaled(366, 568))
splash.show()
splash.showMessage('<h1 style="color:white;">Welcome to use this PyQt5-SplashScreen</h1>', 
                   Qt.AlignTop | Qt.AlignHCenter, Qt.white)    
time.sleep(5)
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
window = Window()
splash.finish(window)     # +++

sys.exit(App.exec()) 

enter image description here