Skip to main content

GUI toolkit to efficiently develop fluid graphical user interfaces for embedded devices and desktop applications

Project description

Slint-python (Beta)

Slint is a UI toolkit that supports different programming languages. Slint-python is the integration with Python.

Warning Slint-python is in a beta phase of development: The APIs while mostly stable, may be subject to further changes. Any changes will be documented in the ChangeLog.

You can track the progress for the Python integration by looking at python-labelled issues at https://github.com/slint-ui/slint/labels/a%3Alanguage-python .

Slint Language Manual

The Slint Language Documentation covers the Slint UI description language in detail.

Prerequisites

Installation

Install Slint with uv or pip from the Python Package Index:

uv add slint

The installation uses binaries provided for macOS, Windows, and Linux for various architectures. If your target platform is not covered by binaries, uv will automatically build Slint from source. If that happens, you will then need some software development tools on your machine, as well as Rust.

Quick Start

  1. Create a new project with uv init.
  2. Add the Slint Python package to your Python project: uv add slint
  3. Create a file called app-window.slint:
import { Button, VerticalBox } from "std-widgets.slint";

export component AppWindow inherits Window {
    in-out property<int> counter: 42;
    callback request-increase-value();
    VerticalBox {
        Text {
            text: "Counter: \{root.counter}";
        }
        Button {
            text: "Increase value";
            clicked => {
                root.request-increase-value();
            }
        }
    }
}
  1. Create a file called main.py:
import slint

# slint.loader will look in `sys.path` for `app-window.slint`.
class App(slint.loader.app_window.AppWindow):
    @slint.callback
    def request_increase_value(self):
        self.counter = self.counter + 1

app = App()
app.run()
  1. Run it with uv run main.py

API Overview

Instantiating a Component

The following example shows how to instantiate a Slint component in Python:

app.slint

export component MainWindow inherits Window {
    callback clicked <=> i-touch-area.clicked;

    in property <int> counter;

    width: 400px;
    height: 200px;

    i-touch-area := TouchArea {}
}

The exported component is exposed as a Python class. To access this class, you have two options:

  1. Call slint.load_file("app.slint"). The returned object is a namespace, that provides the MainWindow class as well as any other explicitly exported component that inherits Window:

    import slint
    components = slint.load_file("app.slint")
    main_window = components.MainWindow()
    
  2. Use Slint's auto-loader, which lazily loads .slint files from sys.path:

    import slint
    # Look for for `app.slint` in `sys.path`:
    main_window = slint.loader.app.MainWindow()
    

    Any attribute lookup in slint.loader is searched for in sys.path. If a directory with the name exists, it is returned as a loader object, and subsequent attribute lookups follow the same logic.

    If the name matches a file with the .slint extension, it is automatically loaded with load_file and the namespace is returned.

    If the file name contains a dash, like app-window.slint, an attribute lookup for app_window tries to locate app_window.slint and then fall back to app-window.slint.

Accessing Properties

Properties declared as out or in-out in .slint files are visible as properties on the component instance.

main_window.counter = 42
print(main_window.counter)

Accessing Globals

Global Singletons are accessible in Python as properties in the component instance.

For example, this Slint code declares a PrinterJobQueue singleton:

export global PrinterJobQueue {
    in-out property <int> job-count;
}

Access it as a property on the component instance by its name:

print("job count:", instance.PrinterJobQueue.job_count)

Note: Global singletons are instantiated once per component. When declaring multiple components for export to Python, each instance has their own associated globals singletons.

Setting and Invoking Callbacks

Callbacks declared in .slint files are visible as callable properties on the component instance. Invoke them as functions to invoke the callback, and assign Python callables to set the callback handler.

In Slint, callbacks are defined using the callback keyword and can be connected to another component's callback using the <=> syntax.

my-component.slint

export component MyComponent inherits Window {
    callback clicked <=> i-touch-area.clicked;

    width: 400px;
    height: 200px;

    i-touch-area := TouchArea {}
}

The callbacks in Slint are exposed as properties and that can be called as functions.

main.py

import slint

component = slint.loader.my_component.MyComponent()
# connect to a callback

def clicked():
    print("hello")

component.clicked = clicked
// invoke a callback
component.clicked();

Another way to set callbacks is to sub-class and use the @slint.callback decorator:

import slint

class Component(slint.loader.my_component.MyComponent):
    @slint.callback
    def clicked(self):
        print("hello")

component = Component()

The @slint.callback() decorator accepts a name argument, if the name of the method does not match the name of the callback in the .slint file. Similarly, a global_name argument can be used to bind a method to a callback in a global singleton.

Type Mappings

Each type used for properties in the Slint Language translates to a specific type in Python. The following table summarizes the mapping:

.slint Type Python Type Notes
int int
float float
string str
color slint.Color
brush slint.Brush
image slint.Image
length float
physical_length float
duration float The number of milliseconds
angle float The angle in degrees
structure dict/Struct When reading, structures are mapped to data classes, when writing dicts are also accepted.
array slint.Model

Arrays and Models

You can set array properties from Python by passing subclasses of slint.Model.

Use the slint.ListModel class to construct a model from an iterable:

component.model = slint.ListModel([1, 2, 3]);
component.model.append(4)
del component.model[0]

When sub-classing slint.Model, provide the following methods:

    def row_count(self):
        """Return the number of rows in your model"""

    def row_data(self, row):
        """Return data at specified row"""

    def set_row_data(self, row, data):
        """For read-write models, store data in the given row. When done call set.notify_row_changed:"
        ..."""
        self.notify_row_changed(row)

When adding or inserting rows, call notify_row_added(row, count) on the super class. Similarly, when removing rows, notify Slint by calling notify_row_removed(row, count).

Structs

Structs declared in Slint and exposed to Python via export are then accessible in the namespace that is returned when instantiating a component.

app.slint

export struct MyData {
    name: string,
    age: int
}

export component MainWindow inherits Window {
    in-out property <MyData> data;
}

main.py

The exported MyData struct can be constructed as follows:

import slint
# Look for for `app.slint` in `sys.path`:
main_window = slint.loader.app.MainWindow()

data = slint.loader.app.MyData(name = "Simon")
data.age = 10
main_window.data = data

Enums

Enums declared in Slint and exposed to Python via export are then accessible in the namespace that is returned when instantiating a component. The enums are subclasses of enum.Enum.

app.slint

export enum MyOption {
    Variant1,
    Variant2
}

export component MainWindow inherits Window {
    in-out property <MyOption> data;
}

main.py

Variants of the exported MyOption enum can be constructed as follows:

import slint
# Look for for `app.slint` in `sys.path`:
main_window = slint.loader.app.MainWindow()

value = slint.loader.app.MyOption.Variant2
main_window.data = value

Asynchronous I/O

Use Python's asyncio library to write concurrent Python code with the async/await syntax.

Slint's event loop is a full-featured asyncio event loop. While the event loop is running, asyncio.get_event_loop() returns a valid loop. To run an async function when starting the loop, pass a coroutine to slint.run_event_loop().

For the common use case of interacting with REST APIs, we recommend the aiohttp library.

Known Limitations

  • Pipes and sub-processes are only supported on Unix-like platforms.

Type Hints

PEP 484 introduces a standard syntax for type annotations to Python, enabling static analysis for type checking, refactoring, and code completion. Popular type checkers include mypy, Pyre, and Astral's ty.

Use Slint's slint-compiler to generate stub .py files for .slint files, which are annotated with type information. These replace the need to call load_file or any use of slint.loader.

  1. Create a new project with uv init.
  2. Add the Slint Python package to your Python project: uv add slint
  3. Create a file called app-window.slint:
import { Button, VerticalBox } from "std-widgets.slint";

export component AppWindow inherits Window {
    in-out property<int> counter: 42;
    callback request-increase-value();
    VerticalBox {
        Text {
            text: "Counter: \{root.counter}";
        }
        Button {
            text: "Increase value";
            clicked => {
                root.request-increase-value();
            }
        }
    }
}
  1. Run the slint-compiler to generate app_window.py: uvx slint-compiler -f python -o app_window.py app-window.slint

  2. Create a file called main.py:

import slint
import app_window

class App(app_window.AppWindow):
    @slint.callback
    def request_increase_value(self):
        self.counter = self.counter + 1

app = App()
app.run()
  1. Run it with uv run main.py

Third-Party Licenses

For a list of the third-party licenses of all dependencies, see the separate Third-Party Licenses page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slint-1.15.1b1.tar.gz (2.1 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

slint-1.15.1b1-cp314-cp314t-manylinux_2_31_armv7l.whl (12.0 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.31+ ARMv7l

slint-1.15.1b1-cp314-cp314t-manylinux_2_31_aarch64.whl (12.4 MB view details)

Uploaded CPython 3.14tmanylinux: glibc 2.31+ ARM64

slint-1.15.1b1-cp313-cp313t-manylinux_2_31_armv7l.whl (12.0 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.31+ ARMv7l

slint-1.15.1b1-cp313-cp313t-manylinux_2_31_aarch64.whl (12.4 MB view details)

Uploaded CPython 3.13tmanylinux: glibc 2.31+ ARM64

slint-1.15.1b1-cp311-abi3-win_amd64.whl (8.7 MB view details)

Uploaded CPython 3.11+Windows x86-64

slint-1.15.1b1-cp311-abi3-manylinux_2_35_x86_64.whl (12.7 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.35+ x86-64

slint-1.15.1b1-cp311-abi3-manylinux_2_31_armv7l.whl (12.0 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.31+ ARMv7l

slint-1.15.1b1-cp311-abi3-manylinux_2_31_aarch64.whl (12.4 MB view details)

Uploaded CPython 3.11+manylinux: glibc 2.31+ ARM64

slint-1.15.1b1-cp311-abi3-macosx_11_0_arm64.whl (7.8 MB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphonesimulator.whl (7.3 MB view details)

Uploaded CPython 3.11+iOS 13.0+ ARM64 Simulator

slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphoneos.whl (7.2 MB view details)

Uploaded CPython 3.11+iOS 13.0+ ARM64 Device

File details

Details for the file slint-1.15.1b1.tar.gz.

File metadata

  • Download URL: slint-1.15.1b1.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slint-1.15.1b1.tar.gz
Algorithm Hash digest
SHA256 9138ac5b4c11c879bb2c18f6ea5811ab66c100c782d81e0c2faa5c664db69b91
MD5 3eed333bfa30235e59c5b793b841f9e5
BLAKE2b-256 82ec90569196c0a444d185a6ba4c57770456088982b74779c086a4332b65b5c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1.tar.gz:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp314-cp314t-manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp314-cp314t-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 38b5f42fb4ea64ab61dcef7c3773057ec83633226b77f41243582c4f65321fa0
MD5 f7294e07dde81bba093374aa978fee69
BLAKE2b-256 93b0789d49a1f1eae692ae34c254f09c1ff66b3a6fe18aa1f12bb42533859734

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp314-cp314t-manylinux_2_31_armv7l.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp314-cp314t-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp314-cp314t-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 da8b551c105768d16c66af887283b34f04012ad23e30bc00e4d7fcddf29ec6ef
MD5 8cfde17619824134c993ac9f1742cd87
BLAKE2b-256 96ad63bbfcb55203a9e93ae20a17f5c074d8ed7ca3d21677836721b7c69c5e49

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp314-cp314t-manylinux_2_31_aarch64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp313-cp313t-manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp313-cp313t-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 c7e09bc36e9a7b67f3f3c918502641d368b84ca635fdbfecb0edf3c8d69ce5ea
MD5 b169825ab4f927e1610e2ab52ae37715
BLAKE2b-256 4f70c5894f9bee2d850223f2477fba0912918e7df34e93d9eee7e9bbeaf10173

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp313-cp313t-manylinux_2_31_armv7l.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp313-cp313t-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp313-cp313t-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 a8ecd787aa978c12ea2bf76eaa790916b2e02fc0e822c1c2deface59462a8299
MD5 227094dea321b47c5673550add036cb8
BLAKE2b-256 0cdc712b173201d414c8854a3aebd342929b442b4b75ccc7a447f359b5bbecb2

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp313-cp313t-manylinux_2_31_aarch64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: slint-1.15.1b1-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 8.7 MB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 45e7a313f82e3f1d61735f39701fd9db037e22aebda733596005d81f38fd94da
MD5 c6e7a60e2c2ff4417817a3cdfe65eaa1
BLAKE2b-256 ea5ebca016f6d71a3964f29fb1125a938cd4903c25a737b6c930226513e70b47

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-win_amd64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 4325ae72819a877f9f45edd59641874ec97169c8c250b92b19b9d8d4c84f2d98
MD5 f9085fe8dea97937200df0af719c37ba
BLAKE2b-256 2167579de27f70a44d06a5e43db70e1543fa8e1f7cabd1b0b6859bced647c7d7

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-manylinux_2_35_x86_64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-manylinux_2_31_armv7l.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-manylinux_2_31_armv7l.whl
Algorithm Hash digest
SHA256 ee224305edf4221deb332ccbdc3915e0e8800482bf9af6b6283ade96a6d3b6fb
MD5 4d42c5f24e76124f3167849598916b0d
BLAKE2b-256 c56f17ff0cbf6d57dee4b36fe45f612a0aae3bb072a9efb1978c8d0fdf5724aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-manylinux_2_31_armv7l.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-manylinux_2_31_aarch64.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-manylinux_2_31_aarch64.whl
Algorithm Hash digest
SHA256 1fa788b3dd093bcdfab812142a4391d0f8ac969660bf27041dbfd02b5c5d51e5
MD5 0b3db55791e9095e4cc00d2a3a7a2e1b
BLAKE2b-256 00f85880f3e485bd7296902dd58f3e2b95b4ca6fb68ba3cfdac43bf28b983c6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-manylinux_2_31_aarch64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a4b810fbdd353e61cb435cd7affb4cfd127558ca3e3b2d0bfaba803e4a5d8917
MD5 419a1e4aa847ade597cf29712c97344b
BLAKE2b-256 c0579ae681ffe8fe95afdb7255a50b55d55e1214ef65e1d4647010bac559e991

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-macosx_11_0_arm64.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphonesimulator.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphonesimulator.whl
Algorithm Hash digest
SHA256 d7c59a3371c56cb29b73e28fc01527c78fbd519fff9855c7ec4e4b3083980f84
MD5 51913f00b20e61ecdd0548deb0cc15a4
BLAKE2b-256 7a59817f1aefaa06924cabcf482d5a6a261347aea83989238626d1c57ff8c4c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphonesimulator.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphoneos.whl.

File metadata

File hashes

Hashes for slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphoneos.whl
Algorithm Hash digest
SHA256 9c73c46a4b476654afe82815c7e37255eee0267863bb98981f0467f5bf4dd268
MD5 22429ff17fe49a98c9f4ab6bb3c93f16
BLAKE2b-256 2bcf26b58c299db0da9d60611f78d1eaaff18b95bb8603cf83fda1423ee74954

See more details on using hashes here.

Provenance

The following attestation bundles were made for slint-1.15.1b1-cp311-abi3-ios_13_0_arm64_iphoneos.whl:

Publisher: upload_pypi.yaml on slint-ui/slint

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page