fix title update

This commit is contained in:
Will McGugan
2023-02-01 18:00:52 +01:00
parent 087654a246
commit 8ce76f4f89
3 changed files with 6 additions and 4 deletions

View File

@@ -3,12 +3,13 @@ from textual.widgets import Button, Header, Label
class MyApp(App[str]): class MyApp(App[str]):
CSS_PATH = "question02.css"
TITLE = "A Question App" TITLE = "A Question App"
SUB_TITLE = "The most important question" SUB_TITLE = "The most important question"
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Header() yield Header()
yield Label("Do you love Textual?") yield Label("Do you love Textual?", id="question")
yield Button("Yes", id="yes", variant="primary") yield Button("Yes", id="yes", variant="primary")
yield Button("No", id="no", variant="error") yield Button("No", id="no", variant="error")

View File

@@ -4,12 +4,13 @@ from textual.widgets import Button, Header, Label
class MyApp(App[str]): class MyApp(App[str]):
CSS_PATH = "question02.css"
TITLE = "A Question App" TITLE = "A Question App"
SUB_TITLE = "The most important question" SUB_TITLE = "The most important question"
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
yield Header() yield Header()
yield Label("Do you love Textual?") yield Label("Do you love Textual?", id="question")
yield Button("Yes", id="yes", variant="primary") yield Button("Yes", id="yes", variant="primary")
yield Button("No", id="no", variant="error") yield Button("No", id="no", variant="error")

View File

@@ -192,7 +192,7 @@ Textual apps have a `title` attribute which is typically the name of your applic
By default, `title` will be set to the name of your App class, and `sub_title` is empty. By default, `title` will be set to the name of your App class, and `sub_title` is empty.
You can change these defaults by defining `TITLE` and `SUB_TITLE` class variables. Here's an example of that: You can change these defaults by defining `TITLE` and `SUB_TITLE` class variables. Here's an example of that:
```py title="question_title01.py" hl_lines="6-7 10" ```py title="question_title01.py" hl_lines="7-8 11"
--8<-- "docs/examples/app/question_title01.py" --8<-- "docs/examples/app/question_title01.py"
``` ```
@@ -203,7 +203,7 @@ Note that the title and subtitle are displayed by the builtin [Header](./../widg
You can also set the title attributes dynamically within a method of your app. The following example sets the title and subtitle in response to a key press: You can also set the title attributes dynamically within a method of your app. The following example sets the title and subtitle in response to a key press:
```py title="question_title02.py" hl_lines="19-21" ```py title="question_title02.py" hl_lines="20-22"
--8<-- "docs/examples/app/question_title02.py" --8<-- "docs/examples/app/question_title02.py"
``` ```