Python 在PyQt5中创建初始屏幕
我想使用Python在PyQt5中创建一个启动屏幕。我搜索了,但在Python 在PyQt5中创建初始屏幕,python,user-interface,pyqt5,splash-screen,Python,User Interface,Pyqt5,Splash Screen,我想使用Python在PyQt5中创建一个启动屏幕。我搜索了,但在Pyqt4中找到了,我对Pyqt4没有任何了解,所以在这种情况下,请帮助我,我会很感激 试试看: import sys from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QApplication, QSplashScreen from PyQt5.QtCore import QTimer
Pyqt4
中找到了,我对Pyqt4没有任何了解,所以在这种情况下,请帮助我,我会很感激
试试看:
import sys
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QDialog, QPushButton, QVBoxLayout, QApplication, QSplashScreen
from PyQt5.QtCore import QTimer
class Dialog(QDialog):
def __init__(self, parent=None):
super(Dialog, self).__init__(parent)
self.b1 = QPushButton('Display screensaver')
self.b1.clicked.connect(self.flashSplash)
layout = QVBoxLayout()
self.setLayout(layout)
layout.addWidget(self.b1)
def flashSplash(self):
self.splash = QSplashScreen(QPixmap('D:/_Qt/img/pyqt.jpg'))
# By default, SplashScreen will be in the center of the screen.
# You can move it to a specific location if you want:
# self.splash.move(10,10)
self.splash.show()
# Close SplashScreen after 2 seconds (2000 ms)
QTimer.singleShot(2000, self.splash.close)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = Dialog()
main.show()
sys.exit(app.exec_())
示例2
import sys
from PyQt5 import QtCore, QtGui, QtWidgets # + QtWidgets
import sys
from PyQt5.QtWidgets import QApplication, QLabel
from PyQt5.QtCore import QTimer, Qt
if __name__ == '__main__':
app = QApplication(sys.argv)
label = QLabel("""
<font color=red size=128>
<b>Hello PyQt, The window will disappear after 5 seconds!</b>
</font>""")
# SplashScreen - Indicates that the window is a splash screen. This is the default type for .QSplashScreen
# FramelessWindowHint - Creates a borderless window. The user cannot move or resize the borderless window through the window system.
label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint)
label.show()
# Automatically exit after 5 seconds
QTimer.singleShot(5000, app.quit)
sys.exit(app.exec_())
导入系统
从PyQt5导入QtCore、QtGui、QtWidgets#+QtWidgets
导入系统
从PyQt5.qtwidts导入QApplication、QLabel
从PyQt5.QtCore导入QTimer,Qt
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
app=QApplication(sys.argv)
label=QLabel(“”)
你好,PyQt,窗口将在5秒后消失
""")
#SplashScreen(溅屏)-表示窗口是溅屏。这是.qsplashsscreen的默认类型
#FramelessWindowHint-创建无边框窗口。用户无法通过窗口系统移动无边框窗口或调整其大小。
label.setWindowFlags(Qt.SplashScreen | Qt.FramelessWindowHint)
label.show()
#5秒后自动退出
QTimer.singleShot(5000,应用程序退出)
sys.exit(app.exec_())
我喜欢在加载主窗口小部件之前添加它,但会稍微褪色-注意,这仅在显示徽标时有用,如果应用程序的加载时间较长,则可以使用如上所示的启动屏幕,以便在显示启动屏幕时允许加载时间:
if __name__ == "__main__":
app = QApplication([])
# Create splashscreen
splash_pix = QtGui.QPixmap('icons/Image.png')
splash = QtGui.QSplashScreen(splash_pix, QtCore.Qt.WindowStaysOnTopHint)
widget = Main()
# add fade to splashscreen
opaqueness = 0.0
step = 0.03
splash.setWindowOpacity(opaqueness)
splash.show()
while opaqueness < 1:
splash.setWindowOpacity(opaqueness)
time.sleep(step) # Sleep for 3 seconds
opaqueness+=(2*step)
time.sleep(1.2)
splash.close()
# Run the normal application
widget.show()
app.exec_()
如果名称=“\uuuuu main\uuuuuuuu”:
app=QApplication([])
#创建飞溅屏幕
splash_pix=QtGui.QPixmap('icons/Image.png'))
splash=QtGui.qsplashsscreen(splash_pix,QtCore.Qt.WindowStaysOnTopHint)
widget=Main()
#添加淡入画面
不透明度=0.0
阶跃=0.03
splash.setWindowOpacity(不透明)
splash.show()
当透明度<1时:
splash.setWindowOpacity(不透明)
时间。睡眠(步骤)#睡眠3秒钟
不透明+=(2*步)
时间。睡眠(1.2)
splash.close()
#运行正常的应用程序
widget.show()
app.exec()
谢谢您的回答,但当我点击按钮时,它只显示灰色屏幕,这让人感到困惑;不是图像。。背后的原因是什么???@sabeenkanwal您必须指定图像的路径self.splash=qsplashsscreen(QPixmap('path/name.jpg'))
。如果您的图像位于当前目录(启动应用程序的位置),您可以简单地指定其名称self.splash=qsplashsscreen(QPixmap('name.jpg'))
我们可以在启动屏幕中仅显示图像吗?@sabeenkanwal I添加了第二个示例