E4 - layouts

layout behavior
QHBoxLayout linear horizontal layout
QVBoxLayout linear vertical layout
QGridLayout in indexable grid xxy
QStackedLayout stacked (z) in front of one another

grid layout.png|500
image: Python GUIs

import sys

from PyQt.QtWidgets import QWidget

from PyQt6.QtGui import QColor, QPalette


class Color(QWidget):
    def __init__(self, color):
        super().__init__()
        self.setAutoFillBackground(True)

        palette = self.palette()
        palette.setColor(QPalette.ColorRole.Window, QColor(color))
        self.setPalette(palette)
        
        import sys
ffrom PyQt6.QtWidgets import QApplication, QMainWindow, QTabWidget


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")

        tabs = QTabWidget()
        tabs.setTabPosition(QTabWidget.TabPosition.West)
        tabs.setMovable(True)

        for color in ["red", "green", "blue", "yellow"]:
            tabs.addTab(Color(color), color)

        self.setCentralWidget(tabs)


app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()

E4 - layouts.png|250