Skip to content

Commit

Permalink
add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Dec 12, 2024
1 parent 318ba2a commit 16a7888
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions website/documentation/content/timer_documentation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,32 @@ def handle_click():
ui.button('Notify after 1 second', on_click=handle_click)


@doc.demo("Don't start immediately", '''
By default, the timer will start immediately.
You can change this behavior by setting the `immediate` parameter to `False`.
This will delay the first execution of the callback by the given interval.
''')
def start_immediately_demo():
from datetime import datetime

label = ui.label()
ui.timer(1.0, lambda: label.set_text(f'{datetime.now():%X}'), immediate=False)


@doc.demo('Global app timer', '''
While `ui.timer` is kind of a UI element that runs in the context of the current page,
you can also use the global `app.timer` for UI-independent timers.
''')
def app_timer_demo():
from nicegui import app

counter = {'value': 0}
app.timer(1.0, lambda: counter.update(value=counter['value'] + 1))

# @ui.page('/')
def page():
ui.label().bind_text_from(counter, 'value', lambda value: f'Count: {value}')
page() # HIDE


doc.reference(ui.timer)

0 comments on commit 16a7888

Please sign in to comment.