Declarative Components

Category Generic PySide6 flet tkinter textual wx Description
Flow Application ✓ QApplication ✓ Page ✓ Tk ✓ App ✓ App
Window ✓ QMainWindow ✓ (Single) ✓ Toplevel ✓ (Single) ✓ Frame
Tabs ✓ QTabWidget ✓ Tabs ✓ Notebook ✓ Tabs
Tab ✓ Tab
Modal
MdiSubWindow ✓ QMdiSubWindow
MdiArea ✓ QMdiArea
Layout HBox ✓ QHBoxLayout ✓ Row ✓ Frame(grid) ✓ Horizontal ✓ BoxSizer
VBox ✓ QVBoxLayout ✓ Column ✓ Frame(grid) ✓ Vertical ✓ BoxSizer
Grid ✓ QGridLayout ✓ GridBagSizer
Spacer ✓ QSpacerItem default weight=1
Splitter ✓ QSplitter drag resizable
Widget Divider ✓ StaticLine
Label ✓ QLabel ✓ Text ✓ Label ✓ Label/Button ✓ StaticText single line
Button ✓ QPushButton ✓ ElevatedButton ✓ Button ✓ Button ✓ Button Clickable single line with visual hint
Checkbox ✓ QCheckBox ✓ Checkbox ✓ Checkbutton ✓ Checkbox ✓ Checkbox
RadioButton ✓ QRadioButton ✓ Radio ✓ Radiobutton ✓ RadioButton ✓ RadioButton
Canvas ✓ (QWidget) ✓ Canvas ✓ Canvas ✓ (Panel)
MatplotlibCanvas ✓ FigureCanvas
TextField ✓ QLineEdit ✓ TextField ✓ Entry ✓ Input ✓ TextCtrl single line text editor
ProgressBar ✓ QProgressBar ✓ ProgressBar ✓ Progressbar ✓ ProgressBar ✓ Gauge
Scroll ✓ QScrollArea ✓ ScrollableContainer ✓ ScrolledPanel default to vertical-only scrollable
Text ✓ QLabel ✓ Text ✓ Label ✓ Text ✓ Label multiline
Html ✓ QLabel ⚠ Text ⚠ Label ⚠ Text
MarkDown ✓ QLabel ✓ Markdown ⚠ Label ✓ Markdown
ComboBox ✓ QComboBox ✓ Combobox Editable Dropdown
Table ✓ QTableView
Tree ✓ QTreeView
MenuBar ✓ QMenuBar
Menu ✓ QMenu
MenuAction ✓ QAction
ToolBar ✓ QToolBar
ToolBarAction ✓ QToolBarAction
Interop ✓ QtInPui
✓ PuiInQt

Imperative Dialogs

Example
Generic PySide6 flet tkinter textual wx Description
OpenDirectory QFileDialog.getExistingDirectory DirDialog
OpenFile QFileDialog.getOpenFileName FileDialog
OpenFiles QFileDialog.getOpenFileNames FileDialog
SaveFile QFileDialog.getSaveFileName FileDialog
Information QMessageBox MessageBox normal notification
Warning QMessageBox MessageBox warning notification
Critical QMessageBox MessageBox critical notification
Confirm QMessageBox MessageDialog yes/no question
Prompt QInputDialog TextEntryDialog

Decorators

@PUIApp


@PUIApp
def Example():
    ...
is equivalent to

class Example(Application):
    def content(self):
        ...

@PUI


@PUI
def SubView():
    ...
is equivalent to

class SubView(PUIView):
    def content(self):
       ...

Callback Interface

All callback interfaces accept an event object as the first argument. Other args/kwargs will be passed through to the callback function. For example

def button_cb(event, data):
    print(data)

Button("button").click(button_cb, 1)
will invoke

button_cb(event, 1)
when the event is emitted.

Event Object

click

dblclick

mousedown

mouseup

mousemove

wheel

input

Triggered when typing in `TextField`

change

Triggered when editing is finished in `TextField`

Declarative Components

Common Modifiers

Application

Top level element of an application

Application().qt(Style="fusion")

Window

flet and textual backends only support single window

Window([title=str][,size=(w,h)][,maximize=bool][,fullscreen=bool])
Modal window
Example

Modal(model[,offValue=None][,title=str][,size=(w,h)][,maximize=bool][,fullscreen=bool])

HBox

Horizontal Linear Layout Container
Example

HBox()

VBox

Vertical Linear Layout Container
Example

VBox()

Grid

Grid Layout Container
Example

with Grid():
    Text("A").grid(row=0, column=0)
    Text("B").grid(row=1, column=0, rowspan=2)

Spacer

Spacer inside linear layout containers
Example

with HBox():
    Text("Left")
    Spacer()
    Text("Right")

Divider

Divider inside linear layout containers
Example

with VBox():
    Text("Top")
    Divider()
    Text("Bottom")

Scroll

Scrollable container
Example

with Scroll().layout(weight=1).scrollY(Scroll.END):
    with VBox():
        for i in range(100):
            Label(f"Row {i+1}")

Button

Single line clickable text with button appearance
Example

Button(text).click(callback, *cb_args, **cb_kwargs)
### Callbacks * .click

Label

Single line clickable text
Example

Label(text).click(callback, *cb_args, **cb_kwargs)
### Callbacks * .click

Text

Multiple line text viewer
Example

Text(text)

Html

HTML viewer (only supported by PySide6 backend)
Example

Html(html)

Markdown

Markdown viewer (not supported by tkinter backend)
Example

Markdown(md)

Combobox

Editable Dropdown List
Example

with ComboBox(editable=True, index_model=state("index"), text_model=state("text")):
    ComboBoxItem("Item 1")
    ComboBoxItem("Item 2")
    ComboBoxItem("Item 3")

with ComboBox(editable=False, text_model=state("text")):
    ComboBoxItem("Item 1", "Value 1")
    ComboBoxItem("Item 2", "Value 2")
    ComboBoxItem("Item 3", "Value 3")

TextField

Single line text editor
Example

TextField(binding, edit_buffer_binding=None)

Callbacks

ProgressBar

Linear progress indicator
Example

ProgressBar(progress `0-1`)

Checkbox

Example

Checkbox(label, model)

Callbacks

RadioButton

Example

RadioButton(label, value, model)

Canvas

Example

def painter(canvas):
    canvas.drawText(x, y, text, w=None, h=None, size=12, color=None, rotate=0, anchor=Anchor.LEFT_TOP)
    canvas.drawLine(x1, y1, x2, y2, color=0xFF0000, width=1)
    canvas.drawPolyline([x1, y2, ..., xn, yn], color=0xFF0000, width=1)
    canvas.drawRect(x1, y1, x2, y2, fill=0xFF0000, stroke=0x00FF00, width=1)
    canvas.drawShapely(shape, fill=0xFF0000, stroke=0x00FF00, width=1)

Canvas(painter)

Callbacks

MatplotlibCanvas

Example

data = [(0,0), (1,3), (2,2)]
def plot(figure, data):
    figure.clear()
    sp = figure.add_subplot(111)
    sp.axes.plot([d[0] for d in data], [d[1] for d in data])

MatplotlibCanvas(plot, data)

Splitter

Splitter(vertical=False)

with Splitter():
    Label("Left")
    Label("Right")

Tabs and Tab

Example

with Tabs():
    with Tab("Tab 1"):
        Label("Tab Content 1")
    with Tab("Tab 2"):
        Label("Tab Content 2")

Table

Table widget
Example with TableNode

with Table():
    with TableNode():
        TableNode("A1")
        TableNode("A2")
    with TableNode():
        TableNode("B1")
        TableNode("B2")
Example with adapter

Table(adapter)

Tree

Single column tree widget
There should be a `TreeTable` for multi/fixed-column trees and a `NestedTable` for variable-column trees, but they have not been implemented yet
Example with TreeNode

with Tree():
    with TreeNode("Root"):
        with TreeNode("Sub 1"):
            TreeNode("Sub 1-1")
            TreeNode("Sub 1-2")
        TreeNode("Sub 2")
        with TreeNode("Sub 3"):
            TreeNode("Sub 3-1")
Example with adapter

Tree(adapter)

Interop

QtInPui

Wrapper for embedding native widget instance into PUI Currently only supported by PySide6 backend
Example

PuiInQt

Wrapper for embedding PUI view into existing QT view hierarchy Currently only supported by PySide6 backend
Example