This repository has been archived by the owner on Jun 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Helper code for Textualize/textual#2854
- Loading branch information
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""https://github.com/Textualize/textual/issues/2854""" | ||
|
||
from textual import on | ||
from textual.app import App, ComposeResult | ||
from textual.containers import Vertical, VerticalScroll | ||
from textual.widgets import Button, Label | ||
|
||
class SelfRemovingLabel(Label): | ||
|
||
def on_mount(self) -> None: | ||
self.set_timer(2, self.remove) | ||
|
||
class RemoveOnTimerApp(App[None]): | ||
|
||
CSS = """ | ||
Label { | ||
margin-bottom: 1; | ||
width: 1fr; | ||
border: solid $warning; | ||
background: $warning 20%; | ||
} | ||
""" | ||
|
||
def compose(self) -> ComposeResult: | ||
with Vertical(): | ||
yield Button("Add self-removing label") | ||
yield VerticalScroll() | ||
|
||
@on(Button.Pressed) | ||
def add_ephemeral_label(self): | ||
self.query_one(VerticalScroll).mount(SelfRemovingLabel("I will remove myself!")) | ||
|
||
if __name__ == "__main__": | ||
RemoveOnTimerApp().run() | ||
|
||
### remove_on_timer.py ends here |