demo.py 581 B

123456789101112131415161718192021
  1. #!/usr/bin/env python3
  2. import time
  3. from nicegui import run, ui # sets NICEGUI_HOST environment variable; if NICEGUI_HOST is set, imports a hull
  4. # unpickling does not import NiceGUI because `run` is implemented outside of nicegui module
  5. def simulate_work():
  6. print('Working...')
  7. time.sleep(1.0)
  8. print('Done.')
  9. # TODO: NiceGUI main_guard to selectively run user code?
  10. # if main_guard:
  11. # print('Doing heavy work...')
  12. ui.button('Work', on_click=lambda: run.cpu_bound(simulate_work))
  13. ui.run(reload=False) # does nothing if NICEGUI_HOST is set
  14. # ui.run() # TODO