Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Yes—you can build a complete PySide6 desktop interface directly in Python. Create widgets, arrange them with layouts, connect signals to behavior, then show the window and start the application event loop. Qt Widgets Designer and .ui files are optional tools for a separate visual-design workflow, not prerequisites.

What you need to create a PySide6 interface in code

PySide6’s Qt Widgets module provides the controls used in classic desktop-style interfaces, while layouts arrange those controls within a window. The official documentation describes Qt Widgets as a set of UI elements for creating classic desktop-style user interfaces: PySide6.QtWidgets.

A code-first interface is a Python widget tree: your program creates the parent window, creates child controls, places them in layouts, and defines what happens when users interact with them. This is the imperative approach described in Qt for Python’s Getting Started guide. Qt Quick is a different approach that describes interfaces with QML; it is not required for a Qt Widgets application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose QWidget or QMainWindow

Use QWidget for a simple window or a custom widget. It is the general base class for widgets and can serve as a top-level window: QWidget documentation.

Use QMainWindow when you want the structure of a conventional application window. It provides a central content area and support for menus, toolbars, dock widgets, and a status bar. Put the main interface inside a central widget rather than assigning a layout directly to the QMainWindow: QMainWindow documentation.

Build a small window entirely in Python

This example creates a window with a label, a text-entry field, and a button. Clicking the button updates the label. It uses layouts to manage geometry and a signal connection to define the button’s behavior.

import sys
from PySide6.QtWidgets import (
    QApplication,
    QLabel,
    QLineEdit,
    QPushButton,
    QVBoxLayout,
    QWidget,
)


class GreetingWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("Python-first PySide6 interface")

        self.message = QLabel("Enter your name")
        self.name_input = QLineEdit()
        self.name_input.setPlaceholderText("Name")
        self.greet_button = QPushButton("Greet")

        layout = QVBoxLayout(self)
        layout.addWidget(self.message)
        layout.addWidget(self.name_input)
        layout.addWidget(self.greet_button)

        self.greet_button.clicked.connect(self.show_greeting)

    def show_greeting(self):
        name = self.name_input.text().strip()
        self.message.setText(f"Hello, {name}!" if name else "Enter your name")


app = QApplication(sys.argv)
window = GreetingWindow()
window.show()
sys.exit(app.exec())

What each part does

  • QApplication sets up the application and runs its event loop.
  • GreetingWindow subclasses QWidget, creates its child controls, and sets a title.
  • QVBoxLayout places the controls in a vertical sequence. Layouts adapt placement to widget size requirements and available space, so they are a practical default over fixed coordinates.
  • clicked.connect(self.show_greeting) connects the button’s signal to a method that handles the interaction.
  • show() makes the window visible; app.exec() keeps the application running and processes user input.

Use QMainWindow when you need application-window features

For an application with menus or a status bar, build on QMainWindow and set a central widget for the main content. The official tutorial demonstrates a Python subclass, a title, a File menu with an Exit action, a status-bar message, and window sizing: Create an empty QMainWindow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import sys
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QWidget


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("My application")

        self.setCentralWidget(QLabel("Main content"))

        exit_action = QAction("Exit", self)
        exit_action.triggered.connect(self.close)
        file_menu = self.menuBar().addMenu("&File")
        file_menu.addAction(exit_action)

        self.statusBar().showMessage("Ready")


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

The window size should suit the actual content and application; any size shown in an example is an illustration, not a universal setting. Add controls to the central widget by giving it a layout, then adding the controls to that layout.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How this differs from Qt Designer and .ui files

Qt Widgets Designer is a drag-and-drop interface for designing forms saved as .ui files. With direct Python construction, you create widgets and layouts in code instead, so you do not need Designer, a .ui file, or a UI conversion/loading step. The Designer workflow is documented at pyside6-designer.

Approach How the interface is authored How the application uses it
Direct Python construction Python code creates widgets and layouts. Run the Python application; no .ui conversion or loading is needed.
Designer .ui workflow A visual form is saved in .ui XML. Convert it to Python with pyside6-uic or load it dynamically with QUiLoader.

Qt for Python documents both .ui options in Using .ui files from Designer or QtCreator with QUiLoader and pyside6-uic. The conversion utility is also documented at pyside6-uic. Those tools are useful if you choose the visual form workflow; they are not part of a code-only interface.

Common implementation choices

  • Prefer layouts to fixed positions. Layouts manage child-widget geometry in response to available space and size requirements.
  • Keep UI creation in a widget class. A QWidget or QMainWindow subclass provides a clear home for controls and interaction methods.
  • Use the main-window APIs for main-window features. Set a central widget for content, then add menus or status-bar messages through the corresponding APIs.
  • Choose the approach that fits the project. Direct Python construction keeps the interface in code; Designer is an optional visual alternative that uses .ui forms.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.