mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
changed to CSS_PATH
This commit is contained in:
@@ -111,7 +111,7 @@ Both Header and Footer are children of the Screen object.
|
||||
|
||||
To further explore the DOM, we're going to build a simple dialog with a question and two buttons. To do this we're going import and use a few more builtin widgets:
|
||||
|
||||
- `texual.layout.Container` For our top-level dialog.
|
||||
- `textual.layout.Container` For our top-level dialog.
|
||||
- `textual.layout.Horizontal` To arrange widgets left to right.
|
||||
- `textual.widgets.Static` For simple content.
|
||||
- `textual.widgets.Button` For a clickable button.
|
||||
@@ -140,13 +140,13 @@ You may recognize some of the elements in the above screenshot, but it doesn't q
|
||||
|
||||
## CSS files
|
||||
|
||||
To add a stylesheet we pass the path to the app with the `css_path` parameter:
|
||||
To add a stylesheet set the `CSS_PATH` classvar to a relative path:
|
||||
|
||||
```python hl_lines="23"
|
||||
```python hl_lines="9"
|
||||
--8<-- "docs/examples/guide/dom4.py"
|
||||
```
|
||||
|
||||
You may have noticed that some of the constructors have additional keyword argument: `id` and `classes`. These are used by the CSS to identify parts of the DOM. We will cover these in the next section.
|
||||
You may have noticed that some of the constructors have additional keyword arguments: `id` and `classes`. These are used by the CSS to identify parts of the DOM. We will cover these in the next section.
|
||||
|
||||
Here's the CSS file we are applying:
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ The first step in building a Textual app is to import the [App][textual.app.App]
|
||||
--8<-- "docs/examples/app/simple01.py"
|
||||
```
|
||||
|
||||
|
||||
### The run method
|
||||
|
||||
To run an app we create an instance and call [run()][textual.app.App.run].
|
||||
@@ -153,9 +154,9 @@ Textual apps can reference [CSS](CSS.md) files which define how your app and wid
|
||||
|
||||
The chapter on [Textual CSS](CSS.md) describes how to use CSS in detail. For now lets look at how your app references external CSS files.
|
||||
|
||||
The following example sets the `css_path` attribute on the app:
|
||||
The following example enables loading of CSS by adding a `CSS_PATH` class variable:
|
||||
|
||||
```python title="question02.py" hl_lines="15"
|
||||
```python title="question02.py" hl_lines="6"
|
||||
--8<-- "docs/examples/app/question02.py"
|
||||
```
|
||||
|
||||
@@ -172,7 +173,9 @@ When `"question02.py"` runs it will load `"question02.css"` and update the app a
|
||||
|
||||
### Classvar CSS
|
||||
|
||||
While external CSS files are recommended for most applications, and enable some cool features like *live editing* (see below), you can also specify the CSS directly within the Python code. To do this you can set the `CSS` class variable on the app which contains the CSS content.
|
||||
While external CSS files are recommended for most applications, and enable some cool features like *live editing*, you can also specify the CSS directly within the Python code.
|
||||
|
||||
To do this set a `CSS` class variable on the app to a string containing your CSS.
|
||||
|
||||
Here's the question app with classvar CSS:
|
||||
|
||||
|
||||
@@ -118,9 +118,8 @@ class LogApp(App):
|
||||
def on_mount(self):
|
||||
self.log(self.tree)
|
||||
|
||||
app = LogApp()
|
||||
if __name__ == "__main__":
|
||||
app.run()
|
||||
LogApp.run()
|
||||
|
||||
```
|
||||
|
||||
|
||||
@@ -172,7 +172,7 @@ Let's look at an example which looks up word definitions from an [api](https://d
|
||||
|
||||
=== "dictionary.py"
|
||||
|
||||
```python title="dictionary.py" hl_lines="26"
|
||||
```python title="dictionary.py" hl_lines="28"
|
||||
--8<-- "docs/examples/events/dictionary.py"
|
||||
```
|
||||
=== "dictionary.css"
|
||||
|
||||
Reference in New Issue
Block a user