main.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  2. from nice_gui import ui
  3. from datetime import datetime
  4. from matplotlib import pyplot as plt
  5. with ui.card():
  6. ui.label('Interactive elements', 'h5')
  7. with ui.row():
  8. with ui.column():
  9. ui.button('Click me!', on_click=lambda: output.set_text('Click'))
  10. ui.checkbox('Check me!', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
  11. ui.switch('Switch me!', on_change=lambda e: output.set_text('Switched' if e.value else 'Unswitched'))
  12. ui.slider(0, 100, on_change=lambda e: output.set_text(e.value))
  13. with ui.column():
  14. ui.radio(['A', 'B', 'C'], on_change=lambda e: output.set_text(e.value))
  15. ui.select(['1', '2', '3'], on_change=lambda e: output.set_text(e.value))
  16. with ui.row():
  17. ui.label('Output:')
  18. output = ui.label()
  19. with ui.card():
  20. ui.label('Timer', 'h5')
  21. time = ui.label()
  22. ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
  23. with ui.card():
  24. ui.label('Matplotlib', 'h5')
  25. with ui.plot(close=False) as plot:
  26. plt.title('Some plot')
  27. plt.plot(range(10), [x**2 for x in range(10)])
  28. def update_plot():
  29. plt.title('Some plot with a second curve')
  30. plt.plot(range(10), [100 - x**2 for x in range(10)])
  31. plot.update()
  32. ui.timer(3.0, update_plot, once=True)
  33. ui.run()