mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
clock example
This commit is contained in:
31
examples/clock.py
Normal file
31
examples/clock.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
An App to show the current time.
|
||||
"""
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from textual.app import App, ComposeResult
|
||||
from textual.widgets import Digits
|
||||
|
||||
|
||||
class ClockApp(App):
|
||||
CSS = """
|
||||
Screen { align: center middle; }
|
||||
Digits { width: auto; }
|
||||
"""
|
||||
|
||||
def compose(self) -> ComposeResult:
|
||||
yield Digits("")
|
||||
|
||||
def on_ready(self) -> None:
|
||||
self.update_clock()
|
||||
self.set_interval(1, self.update_clock)
|
||||
|
||||
def update_clock(self) -> None:
|
||||
clock = datetime.now().time()
|
||||
self.query_one(Digits).update(f"{clock:%T}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = ClockApp()
|
||||
app.run()
|
||||
Reference in New Issue
Block a user