PyQt5 Window with "Hello, PyQt!" Label

  • Share this:

Code introduction


Create a simple PyQt5 window with a label displaying the text “Hello, PyQt!”.


Technology Stack : PyQt5

Code Type : PyQt5 GUI Application

Code Difficulty : Intermediate


                
                    
import random
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout

def create_random_window(title):
    app = QApplication([])
    window = QWidget()
    window.setWindowTitle(title)
    label = QLabel("Hello, PyQt!")
    layout = QVBoxLayout()
    layout.addWidget(label)
    window.setLayout(layout)
    window.show()
    return window                
              
Tags: