Minimal Rio Intro

Jan 04, 2025 pm 08:22 PM

In early November I saw a release announcement for Rio (https://rio.dev), an upcoming Python library for creating user interfaces. I have years of experience using Qt with Python and always interested in seeing new approaches.

I went through the Tic Tac Toe tutorial and found a lot of things I liked. I was initially impressed by the simplicity of writing interfaces using component classes. The interface runs through an HTML document, which is completely encapsulated by the library. This gives many possibilities on how and where Rio applications are run. Rio optionally includes a standalone webview application. However, I critically disliked the included rio command line tool and the initial project structure it creates.

I think Rio deserves a lighter weight tutorial that strips the boilerplate and abstractions to show the potential this library has. Let's start from nothing and discover how Rio feels building it up for ourselves. I found getting started with uv to be as simple as I'd hoped.

uv init minirio --no-readme --no-pin-python --vcs none
cd minirio
uv add rio-ui[window]
Copy after login

The optional [window] feature installs the many dependencies needed to run the standalone app. Also be aware I needed to use ==9.3 on Windows due to missing pyside builds.

Let's use the minimal code needed to build this application.

Minimal Rio Intro

import rio

class Greeting(rio.Component):
    name: str = 'World'
    def build(self):
        return rio.Row(
            rio.Icon('material/star', align_x=0.8, align_y=0.5),
            rio.Markdown(f'Hello, **{self.name}**', align_y=0.5),
        )

if __name__ == '__main__':
    app = rio.App(build=Greeting)
    app.run_in_window()
Copy after login

This is a regular Python script. Run it with your python interpreter.

uv run hello.py
Copy after login

A component is little more than a build method that returns a component and a state defined on the class. You do not define __init__ or other typical boilerplate. You can replace the run_in_window with a run_as_web_server and interact with this application in your browser.

It takes very little to add some interactivity. Here is a similar component that adds a checkbox and styling.

gradient = rio.LinearGradientFill(
    (rio.Color.RED, 0), (rio.Color.PINK, .3),
)

class Greeting2(rio.Component):
    checked: bool = False

    def build(self):
        style = rio.TextStyle(fill=gradient) if self.checked else 'text'
        return rio.Row(
            rio.Checkbox(is_on=self.bind().checked),
            rio.Text('Roses are red.',>



<p>This is using self.bind() to create a two-way binding between the checkbox state and an attribute. Alternatively, it is straightforward to assign the checkbox's on_change argument to any method and change attributes of self as desired.</p>

<p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173599336588947.jpg" class="lazy" alt="Minimal Rio Intro"></p>

<p>Find more complete examples and documentation on the Rio project website. Personally, I'm not yet ready to leave the world of Qt and Pyside, but I also think there's enough in Rio to keep an eye on.</p>
Copy after login
  • https://rio.dev/examples
  • https://rio.dev/docs
  • https://github.com/rio-labs/rio

The above is the detailed content of Minimal Rio Intro. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve the permissions problem encountered when viewing Python version in Linux terminal? How to solve the permissions problem encountered when viewing Python version in Linux terminal? Apr 01, 2025 pm 05:09 PM

Solution to permission issues when viewing Python version in Linux terminal When you try to view Python version in Linux terminal, enter python...

How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? How to avoid being detected by the browser when using Fiddler Everywhere for man-in-the-middle reading? Apr 02, 2025 am 07:15 AM

How to avoid being detected when using FiddlerEverywhere for man-in-the-middle readings When you use FiddlerEverywhere...

How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? How to efficiently copy the entire column of one DataFrame into another DataFrame with different structures in Python? Apr 01, 2025 pm 11:15 PM

When using Python's pandas library, how to copy whole columns between two DataFrames with different structures is a common problem. Suppose we have two Dats...

How does Uvicorn continuously listen for HTTP requests without serving_forever()? How does Uvicorn continuously listen for HTTP requests without serving_forever()? Apr 01, 2025 pm 10:51 PM

How does Uvicorn continuously listen for HTTP requests? Uvicorn is a lightweight web server based on ASGI. One of its core functions is to listen for HTTP requests and proceed...

How to solve permission issues when using python --version command in Linux terminal? How to solve permission issues when using python --version command in Linux terminal? Apr 02, 2025 am 06:36 AM

Using python in Linux terminal...

How to teach computer novice programming basics in project and problem-driven methods within 10 hours? How to teach computer novice programming basics in project and problem-driven methods within 10 hours? Apr 02, 2025 am 07:18 AM

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...

How to get news data bypassing Investing.com's anti-crawler mechanism? How to get news data bypassing Investing.com's anti-crawler mechanism? Apr 02, 2025 am 07:03 AM

Understanding the anti-crawling strategy of Investing.com Many people often try to crawl news data from Investing.com (https://cn.investing.com/news/latest-news)...

See all articles