mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fancier docs
This commit is contained in:
@@ -4,17 +4,57 @@ Welcome to the [Textual](https://github.com/Textualize/textual) framework docume
|
||||
|
||||
<hr>
|
||||
|
||||
Textual is a Python framework for building applications that run within your terminal.
|
||||
Textual is a framework for building applications that run within your terminal. Such Text User Interfaces (TUIs) have a number of advantages over traditional web and desktop apps.
|
||||
|
||||
Text User Interfaces (TUIs) have a number of benefits:
|
||||
<div class="grid cards" markdown>
|
||||
|
||||
- **Quick to develop:** Really rapid app development with a modern Python API.
|
||||
- **Low requirements:** Textual apps anywhere with a Python interpreter, even single-board computers.
|
||||
- **Cross platform:** The same code will run on Linux, Windows, MacOS and more.
|
||||
- **Remote:** Fully featured UIs can run over SSH.
|
||||
- **CLI integration:** Textual apps integrate with your shell and other CLI tools.
|
||||
- :material-clock-fast:{ .lg .middle } :material-language-python:{. lg .middle } __Rapid development__
|
||||
|
||||
---
|
||||
|
||||
Uses your existing Python skills to build beautiful user interfaces.
|
||||
|
||||
|
||||
- :material-raspberry-pi:{ .lg .middle } __Low requirements__
|
||||
|
||||
---
|
||||
|
||||
Low system requirements. Run Textual on a single board computer if you want to.
|
||||
|
||||
|
||||
|
||||
- :material-microsoft-windows:{ .lg .middle } :material-apple:{ .lg .middle } :fontawesome-brands-linux:{ .lg .middle } __Cross platform__
|
||||
|
||||
---
|
||||
|
||||
Textual runs just about everywhere.
|
||||
|
||||
|
||||
|
||||
- :material-network:{ .lg .middle } __Remote__
|
||||
|
||||
---
|
||||
|
||||
Textual apps can run over SSH.
|
||||
|
||||
|
||||
- :fontawesome-solid-terminal:{ .lg .middle } __CLI Integration__
|
||||
|
||||
---
|
||||
|
||||
Textual apps can be launched and run from the command prompt.
|
||||
|
||||
|
||||
|
||||
- :material-scale-balance:{ .lg .middle } __Open Source, MIT__
|
||||
|
||||
---
|
||||
|
||||
Textual is licensed under MIT.
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
Textual TUIs are quick and easy to build with pure Python (not to mention _fun_).
|
||||
|
||||
<hr>
|
||||
|
||||
|
||||
@@ -35,6 +35,10 @@ python stopwatch.py
|
||||
|
||||
## Type hints (in brief)
|
||||
|
||||
!!! tip inline end
|
||||
|
||||
Type hints are entirely optional in Textual. We've included them in the example code but it's up to you wether you add them to your own projects.
|
||||
|
||||
We're a big fan of Python type hints at Textualize. If you haven't encountered type hinting, its a way to express the types of your data, parameters, and return values. Type hinting allows tools like [Mypy](https://mypy.readthedocs.io/en/stable/) to catch potential bugs before your code runs.
|
||||
|
||||
The following function contains type hints:
|
||||
@@ -49,10 +53,6 @@ def repeat(text: str, count: int) -> str:
|
||||
- Return types follow `->`. So `-> str:` indicates that this method returns a string.
|
||||
|
||||
|
||||
!!! note
|
||||
|
||||
Type hints are entirely optional in Textual. We've included them in the example code but it's up to you wether you add them to your own projects.
|
||||
|
||||
## The App class
|
||||
|
||||
The first step in building a Textual app is to import and extend the `App` class. Here's our basic app class with a few methods we will cover below.
|
||||
@@ -175,14 +175,13 @@ self.styles.background = "blue"
|
||||
self.styles.color = "white"
|
||||
```
|
||||
|
||||
While its possible to set all styles for an app this way, Textual prefers to use CSS.
|
||||
|
||||
CSS files are data files loaded by your app which contain information about styles to apply to your widgets.
|
||||
|
||||
!!! note
|
||||
!!! info inline end
|
||||
|
||||
Don't worry if you have never worked with CSS before. The dialect of CSS we use is greatly simplified over web based CSS and easy to learn!
|
||||
|
||||
|
||||
While its possible to set all styles for an app this way, it is rarely necessary. Textual has support for CSS (Cascading Style Sheets), a technology used by web browsers. CSS files are data files loaded by your app which contain information about styles to apply to your widgets.
|
||||
|
||||
Let's add a CSS file to our application.
|
||||
|
||||
```python title="stopwatch03.py" hl_lines="39"
|
||||
|
||||
Reference in New Issue
Block a user