import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout class MainWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Example') self.setGeometry(100, 100, 400, 400) vbox = QVBoxLayout(self) vbox.addWidget(QWidget()) vbox.setContentsMargins(10, 20, 10, 20) if __name__ == '__main__': app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())In this example, we create a window with a QVBoxLayout and add a widget to it. We then set the contents margins of the QVBoxLayout to 10 pixels on the left and right and 20 pixels on the top and bottom. This function is available in the PyQt5.QtWidgets library.