Skip to content

Datetime picker with the current date pre-selected (as default) #2361

Answered by jrobinAV
s-wel asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @s-wel,

Your date visual element is bound to the state.start_time variable, initialized at the application start. Then, your variable is never changed, so its value is always the same.

I am not sure I understand your use case.

1. You want to initialize your variable at the user session creation

You can use the on_init callback to initialize state variables when a new user connects, such as:

from datetime import datetime, timedelta

from taipy.gui import Gui, Markdown

def on_init(state):
    state.current_time = datetime.now()

if __name__ == "__main__":
    current_time = datetime.now()
    gui = Gui(Markdown("<|{current_time}|date|with_time|format=dd/MM/yyyy HH:mm:ss|>"))
    gui.run()

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by jrobinAV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants