File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments