Files
textual/docs/examples/widgets/clock.py
Will McGugan 49281b3f27 Digits (#3073)
* Digits

* digits widget

* update requires str

* digits docs

* simplify

* tweak docs

* snapshot test

* change name

* simplify

* docs

* Update _digits.py superfluous import

* Update _digits.py docstring

* address review

* formatting

* Update tests/snapshot_tests/snapshot_apps/digits.py

Co-authored-by: Dave Pearson <davep@davep.org>

---------

Co-authored-by: Dave Pearson <davep@davep.org>
2023-08-09 10:25:17 +01:00

32 lines
622 B
Python

from datetime import datetime
from textual.app import App, ComposeResult
from textual.widgets import Digits
class ClockApp(App):
CSS = """
Screen {
align: center middle;
}
#clock {
width: auto;
}
"""
def compose(self) -> ComposeResult:
yield Digits("", id="clock")
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()