Ich mache einen PyQt5-Startbildschirm in PyQt, der einen Countdown innerhalb eines Splash-Bildes erstellt, aber das Skript verhält sich nicht richtig und es hat jedes Mal ein anderes Ergebnis .Wie verwende ich time.sleep und mache jede Sekunde etwas anderes
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5.QtGui import QFont, QPixmap
from PyQt5.QtWidgets import QSplashScreen
import os
import sys
import time
from time import sleep
count = [1,2,3,4,5]
def Splash(self):
app.processEvents()
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
font = splash.font()
font.setPixelSize(16)
font.setWeight(QFont.Bold)
splash.setFont(font)
#splash.showMessage(str(count[0]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
#splash.show()
for i in range(0, 10):
time.sleep(1)
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
splash.showMessage(str(count[0]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
QtWidgets.QApplication.processEvents()
splash.show()
time.sleep(1)
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
splash.showMessage(str(count[1]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
QtWidgets.QApplication.processEvents()
splash.show()
time.sleep(1)
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
splash.showMessage(str(count[2]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
QtWidgets.QApplication.processEvents()
splash.show()
time.sleep(1)
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
splash.showMessage(str(count[3]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
QtWidgets.QApplication.processEvents()
splash.show()
time.sleep(1)
splash = QtWidgets.QSplashScreen(QtGui.QPixmap("22.png"))
splash.showMessage(str(count[4]), QtCore.Qt.AlignHCenter | QtCore.Qt.AlignBottom, QtCore.Qt.white)
QtWidgets.QApplication.processEvents()
splash.show()
Kurz Bedingungen: Wie verwende ich time.sleep(), und jede Sekunde etwas anderes tun. Irgendwelche Vorschläge?
import time
for i in range(0, 10):
time.sleep(1)
print "1"
time.sleep(1)
print "2"
time.sleep(1)
print "3"
time.sleep(1)
print "4"
time.sleep(1)
print "5"
die Antwort von dot.PY gemacht tat der Trick thx Sie können entweder eine bedingte Anweisung zu Schleife nur bis i <= 4 –