11
22# Frequently Asked Questions
33- [ Does Textual support images?] ( #does-textual-support-images )
4+ - [ How do I center a widget in a screen?] ( #how-do-i-center-a-widget-in-a-screen )
5+ - [ How do I pass arguments to an app?] ( #how-do-i-pass-arguments-to-an-app )
46
57<a name =" does-textual-support-images " ></a >
68## Does Textual support images?
@@ -9,6 +11,70 @@ Textual doesn't have built in support for images yet, but it is on the [Roadmap]
911
1012See also the [ rich-pixels] ( https://github.com/darrenburns/rich-pixels ) project for a Rich renderable for images that works with Textual.
1113
14+ <a name =" how-do-i-center-a-widget-in-a-screen " ></a >
15+ ## How do I center a widget in a screen?
16+
17+ To center a widget within a container use
18+ [ ` align ` ] ( https://textual.textualize.io/styles/align/ ) . But remember that
19+ ` align ` works on the * children* of a container, it isn't something you use
20+ on the child you want centered.
21+
22+ For example, here's an app that shows a ` Button ` in the middle of a
23+ ` Screen ` :
24+
25+ ``` python
26+ from textual.app import App, ComposeResult
27+ from textual.widgets import Button
28+
29+ class ButtonApp (App ):
30+
31+ CSS = """
32+ Screen {
33+ align: center middle;
34+ }
35+ """
36+
37+ def compose (self ) -> ComposeResult:
38+ yield Button(" PUSH ME!" )
39+
40+ if __name__ == " __main__" :
41+ ButtonApp().run()
42+ ```
43+
44+ <a name =" how-do-i-pass-arguments-to-an-app " ></a >
45+ ## How do I pass arguments to an app?
46+
47+ When creating your ` App ` class, override ` __init__ ` as you would when
48+ inheriting normally. For example:
49+
50+ ``` python
51+ from textual.app import App, ComposeResult
52+ from textual.widgets import Static
53+
54+ class Greetings (App[None ]):
55+
56+ def __init__ (self , greeting : str = " Hello" , to_greet : str = " World" ) -> None :
57+ self .greeting = greeting
58+ self .to_greet = to_greet
59+ super ().__init__ ()
60+
61+ def compose (self ) -> ComposeResult:
62+ yield Static(f " { self .greeting} , { self .to_greet} " )
63+ ```
64+
65+ Then the app can be run, passing in various arguments; for example:
66+
67+ ``` python
68+ # Running with default arguments.
69+ Greetings().run()
70+
71+ # Running with a keyword arguyment.
72+ Greetings(to_greet = " davep" ).run()
73+
74+ # Running with both positional arguments.
75+ Greetings(" Well hello" , " there" ).run()
76+ ```
77+
1278<hr >
1379
1480Generated by [ FAQtory] ( https://github.com/willmcgugan/faqtory )
0 commit comments