Skip to content

Commit 192e3f9

Browse files
authored
Merge pull request #1419 from davep/faq-pass-args-to-app
Add a FAQ about passing arguments to an application
2 parents 85b1d0c + 14d1cf2 commit 192e3f9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: "How do I pass arguments to an app?"
3+
alt_titles:
4+
- "pass arguments to an application"
5+
- "pass parameters to an app"
6+
- "pass parameters to an application"
7+
---
8+
9+
When creating your `App` class, override `__init__` as you would when
10+
inheriting normally. For example:
11+
12+
```python
13+
from textual.app import App, ComposeResult
14+
from textual.widgets import Static
15+
16+
class Greetings(App[None]):
17+
18+
def __init__(self, greeting: str="Hello", to_greet: str="World") -> None:
19+
self.greeting = greeting
20+
self.to_greet = to_greet
21+
super().__init__()
22+
23+
def compose(self) -> ComposeResult:
24+
yield Static(f"{self.greeting}, {self.to_greet}")
25+
```
26+
27+
Then the app can be run, passing in various arguments; for example:
28+
29+
```python
30+
# Running with default arguments.
31+
Greetings().run()
32+
33+
# Running with a keyword arguyment.
34+
Greetings(to_greet="davep").run()
35+
36+
# Running with both positional arguments.
37+
Greetings("Well hello", "there").run()
38+
```

0 commit comments

Comments
 (0)