E1 - getting started with PyQT
event loop
QApplicationclass is the core of every QT application- only one instance is needed
- it holds the event loop - the core loop which governs the user interaction with the GUI

image: M Fitzpatrick, Create DUI Applications with Python & Qt6, 6th Edition
- each interaction generates an event, placed on the event queue
- the event handler deals with the event, and passes the control back to the loop to wait for more events
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()
- to create custom windows, subclass
QMainWindow
## 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()