mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
clock example
This commit is contained in:
22
docs/examples/timers/clock.py
Normal file
22
docs/examples/timers/clock.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user