E1 - getting started with PyQT

event loop

event loop-1.png|500
image: M Fitzpatrick, Create DUI Applications with Python & Qt6, 6th Edition

import sys
from PyQt6.QtWidgets import QApplication, QPushButton

## creating an instance of the application
app = QApplication(sys.argv)

## creating an instance of a button
window = QPushButton("Push Me")
window.show() #hidden by default

## start the event loop
app.exec()
## creating a sub class
class MainWindow(QMainWindow):

	##including the setup, allwing the window behviour to be self contained
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")
        
        button = QPushButton("Press Me!")
        
        self.setFixedSize(QSize(400, 300)) # set the window size to 400x300 px
        self.setMinimumSize(QSize(200, 300))
        self.setMaximumSize(QSize(600, 300))  

        ## set the central widget of the window.
        self.setCentralWidget(button)
        
        
## assigning the subclass to a variable
window = MainWindow()
window.show()