Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
✨ Helper code for Textualize/textual#2854
Browse files Browse the repository at this point in the history
  • Loading branch information
davep committed Jun 28, 2023
1 parent f275b62 commit 51df428
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions remove_on_timer.py
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

0 comments on commit 51df428

Please sign in to comment.