From 9e405c3e0af293fb9989a4a4bbd5a9ed8cca0868 Mon Sep 17 00:00:00 2001 From: Will McGugan Date: Sat, 7 Aug 2021 12:09:16 +0100 Subject: [PATCH] clock example --- docs/examples/timers/clock.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 docs/examples/timers/clock.py diff --git a/docs/examples/timers/clock.py b/docs/examples/timers/clock.py new file mode 100644 index 000000000..54764568e --- /dev/null +++ b/docs/examples/timers/clock.py @@ -0,0 +1,22 @@ +from datetime import datetime + +from rich.align import Align + +from textual.app import App +from textual.widget import Widget + + +class Clock(Widget): + async def on_mount(self, event): + self.set_interval(1, callback=self.refresh) + + def render(self) -> Align: + time = datetime.now().strftime("%X") + return Align.center(time, vertical="middle") + +class ClockApp(App): + async def on_mount(self, event): + await self.view.dock(Clock()) + + +ClockApp.run()