Skip to content

Instantly share code, notes, and snippets.

@345161974
Created March 15, 2017 13:02
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save 345161974/8897f9230006d51803c987122b3d4f17 to your computer and use it in GitHub Desktop.
Save 345161974/8897f9230006d51803c987122b3d4f17 to your computer and use it in GitHub Desktop.
PyQt SplashScreen Demo
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import time
class Form(QDialog):
""" Just a simple dialog with a couple of widgets
"""
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.browser = QTextBrowser()
self.setWindowTitle('Just a dialog')
self.lineedit = QLineEdit("Write something and press Enter")
self.lineedit.selectAll()
layout = QVBoxLayout()
layout.addWidget(self.browser)
layout.addWidget(self.lineedit)
self.setLayout(layout)
self.lineedit.setFocus()
self.connect(self.lineedit, SIGNAL("returnPressed()"),
self.update_ui)
def update_ui(self):
self.browser.append(self.lineedit.text())
if __name__ == "__main__":
import sys, time
app = QApplication(sys.argv)
# Create and display the splash screen
splash_pix = QPixmap('img/bee2.jpg')
splash = QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
splash.setEnabled(False)
# splash = QSplashScreen(splash_pix)
# adding progress bar
progressBar = QProgressBar(splash)
progressBar.setMaximum(10)
progressBar.setGeometry(0, splash_pix.height() - 50, splash_pix.width(), 20)
# splash.setMask(splash_pix.mask())
splash.show()
splash.showMessage("<h1><font color='green'>Welcome BeeMan!</font></h1>", Qt.AlignTop | Qt.AlignCenter, Qt.black)
for i in range(1, 11):
progressBar.setValue(i)
t = time.time()
while time.time() < t + 0.1:
app.processEvents()
# Simulate something that takes time
time.sleep(1)
form = Form()
form.show()
splash.finish(form)
sys.exit(app.exec_())
@345161974
Copy link
Author

the effect:
pyqt_splash_screen_demo2

@SManAT
Copy link

SManAT commented Jun 6, 2020

very nice, helped me a lot.
ty!

@ariel-avi
Copy link

Nice! thanks!

@crystalattice
Copy link

I tried several different tutorials but only by using this one was I able to finally get it working correctly. Thank you.

@SManAT
Copy link

SManAT commented Apr 2, 2021

nice to hear!
gl & hf

@ABHILASHPRATAPSINGH
Copy link

Awesome sir. Thanks a lot for this solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment