import sys from PySide2.QtWidgets import QApplication, QLabel app = QApplication(sys.argv) label = QLabel('Hello, World!') label.adjustSize() label.show() sys.exit(app.exec_())
import sys from PySide2.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget app = QApplication(sys.argv) main_window = QMainWindow() widget = QWidget() layout = QVBoxLayout(widget) main_window.setCentralWidget(widget) label = QLabel('This is a long text that needs to be wrapped to fit in the available area of the widget.') label.setWordWrap(True) layout.addWidget(label) label.adjustSize() main_window.show() sys.exit(app.exec_())The above code creates a QMainWindow window with a single QVBoxLayout widget as its central widget. A QLabel widget is added to the vertical layout, which displays a long text that needs to be wrapped to fit within the available area of the widget. The setWordWrap method is called on the label widget to enable text wrapping. The adjustSize method is called on the label widget to resize it so that all the wrapped text fits within the available area. In both examples, the PySide2.QtWidgets package is used to create the GUI.