Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import signal
- from PySide6.QtCore import Qt, QTimer
- from PySide6.QtWidgets import QApplication, QSplashScreen, QVBoxLayout, QLabel
- from PySide6.QtGui import QPixmap, QFont, QFontDatabase
- class SplashScreen(QSplashScreen):
- def __init__(self):
- super().__init__()
- self.setFixedSize(534, 300)
- # Define layout as an instance variable
- self.vbox = QVBoxLayout()
- self.setContentsMargins(0, 0, 0, 0)
- self.vbox.setAlignment(Qt.AlignTop | Qt.AlignLeft)
- # Set the layout for the splash screen
- self.setLayout(self.vbox)
- self.setWindowTitle("AppName")
- self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
- self.setWindowOpacity(1)
- # Add external fonts
- # QFontDatabase.addApplicationFont("fonts/Aligator.otf")
- # Create a label to display the background image
- self.splash_img = QLabel(self)
- self.splash_img.setAlignment(Qt.AlignCenter | Qt.AlignTop) # Center the image within the window
- self.splash_img.setPixmap(QPixmap("icon.png"))
- self.splash_img.setStyleSheet("padding: 0;")
- self.splash_img.setScaledContents(True)
- # Create labels for text
- app_name_label = QLabel("AppName", self)
- # app_name_label.setFont(QFont("Aligator", 75))
- app_name_label.setAlignment(Qt.AlignCenter | Qt.AlignTop) # Center the text horizontally
- app_name_label.setStyleSheet("color: black; padding: 0;")
- self.vbox.addWidget(app_name_label)
- version_label = QLabel("Version Number", self)
- version_label.setStyleSheet("color: black; padding: 0;")
- version_label.setAlignment(Qt.AlignBottom)
- self.vbox.addWidget(version_label)
- programmer_label = QLabel("Written by Name", self)
- programmer_label.setStyleSheet("color: black; padding: 0;")
- programmer_label.setAlignment(Qt.AlignBottom)
- self.vbox.addWidget(programmer_label)
- copyright_label = QLabel("Copyright Year, Cute Saying Here", self)
- copyright_label.setStyleSheet("color: black; padding: 0;")
- copyright_label.setAlignment(Qt.AlignBottom)
- self.vbox.addWidget(copyright_label)
- def showEvent(self, event):
- super().showEvent(event)
- # Resize the background label to fill the whole screen
- self.splash_img.setFixedSize(self.size())
- def install_ctrlc_handler(app):
- def ctrlc_handler(sig=None, frame=None):
- app.closeAllWindows() # this makes sure the MainWindow's .close() method gets called
- app.quit()
- # grab the keyboard interrupt signal
- signal.signal(signal.SIGINT, ctrlc_handler)
- # empty timer callback
- def update():
- pass
- # create timer to force python interpreter to get some runtime
- app._ctrlc_timer = QTimer()
- app._ctrlc_timer.timeout.connect(update)
- app._ctrlc_timer.start(10)
- if __name__ == "__main__":
- app = QApplication(sys.argv)
- install_ctrlc_handler(app)
- splash = SplashScreen()
- splash.show()
- # Simulate some loading time
- import time
- time.sleep(1)
- sys.exit(app.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement