import sys from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QLabel app = QApplication(sys.argv) window = QWidget() label_1 = QLabel("Hello") label_2 = QLabel("World") layout = QHBoxLayout() layout.addWidget(label_1) layout.addWidget(label_2) window.setLayout(layout) window.show() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QHBoxLayout, QPushButton app = QApplication(sys.argv) window = QWidget() button_1 = QPushButton("Ok") button_2 = QPushButton("Cancel") layout = QHBoxLayout() layout.addWidget(button_1) layout.addWidget(button_2) window.setLayout(layout) window.show() sys.exit(app.exec_())In this example, we create a window and add two push buttons to a horizontal layout using the QHBoxLayout.addWidget() method. The push buttons are then added to the window using the setLayout() method. These examples are using the PyQt5 package library.