Modal basicsΒΆ
Examples of using modals in Viser.
1import time
2
3import viser
4
5
6def main():
7 server = viser.ViserServer()
8
9 @server.on_client_connect
10 def _(client: viser.ClientHandle) -> None:
11 with client.gui.add_modal("Modal example"):
12 client.gui.add_markdown(
13 "**The input below determines the title of the modal...**"
14 )
15
16 gui_title = client.gui.add_text(
17 "Title",
18 initial_value="My Modal",
19 )
20
21 modal_button = client.gui.add_button("Show more modals")
22
23 @modal_button.on_click
24 def _(_) -> None:
25 with client.gui.add_modal(gui_title.value) as modal:
26 client.gui.add_markdown("This is content inside the modal!")
27 client.gui.add_button("Close").on_click(lambda _: modal.close())
28
29 while True:
30 time.sleep(0.15)
31
32
33if __name__ == "__main__":
34 main()