Merge branch 'main' of github.com:davep/textual

This commit is contained in:
Dave Pearson
2022-12-21 10:41:16 +00:00
2 changed files with 72 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
---
title: "How do I center a widget in a screen?"
alt_titles:
- "centre a widget"
- "center a control"
- "centre a control"
---
To center a widget within a container use
[`align`](https://textual.textualize.io/styles/align/). But remember that
`align` works on the *children* of a container, it isn't something you use
on the child you want centered.
For example, here's an app that shows a `Button` in the middle of a
`Screen`:
```python
from textual.app import App, ComposeResult
from textual.widgets import Button
class ButtonApp(App):
CSS = """
Screen {
align: center middle;
}
"""
def compose(self) -> ComposeResult:
yield Button("PUSH ME!")
if __name__ == "__main__":
ButtonApp().run()
```

View File

@@ -0,0 +1,38 @@
---
title: "How do I pass arguments to an app?"
alt_titles:
- "pass arguments to an application"
- "pass parameters to an app"
- "pass parameters to an application"
---
When creating your `App` class, override `__init__` as you would when
inheriting normally. For example:
```python
from textual.app import App, ComposeResult
from textual.widgets import Static
class Greetings(App[None]):
def __init__(self, greeting: str="Hello", to_greet: str="World") -> None:
self.greeting = greeting
self.to_greet = to_greet
super().__init__()
def compose(self) -> ComposeResult:
yield Static(f"{self.greeting}, {self.to_greet}")
```
Then the app can be run, passing in various arguments; for example:
```python
# Running with default arguments.
Greetings().run()
# Running with a keyword arguyment.
Greetings(to_greet="davep").run()
# Running with both positional arguments.
Greetings("Well hello", "there").run()
```