Digital Clock Component with Date #343
Diegiwg
started this conversation in
Show and tell
Replies: 2 comments 6 replies
-
very nice and very clean method. I will try for sure |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for sharing! I'm just wondering, why do you need so much JavaScript? Do you really need the client time? If not, you can achieve the same result with pure Python: from datetime import datetime
from nicegui import ui
with ui.card().classes('column items-center gap-0'):
date = ui.label().style('font-size: 2rem')
time = ui.label()
ui.timer(1.0, lambda: date.set_text(datetime.now().strftime('%d/%m/%Y')))
ui.timer(0.1, lambda: time.set_text(datetime.now().strftime('%H:%M:%S')))
ui.run() |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I needed to build a clock for my application, and I did the following:
I wrote the following python code in a file called clock.py.
The
import javascript
and thejavascript.fetch
function are responsible for fetching the javascript code (in string) in the clock.js file, available in a static folder with ui.add_static_files.Javascript code responsible for updating the Clock (in clock.js):
[date, time] is receiving a
toLocaleString
object in PT-BR, so this part has to be properly analyzed and modified to match your own language.Now to use it, just
await clock()
anywhere you want the Digital ClockBeta Was this translation helpful? Give feedback.
All reactions