main.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. ui.input('Text input', on_change=lambda e: output.set_text(e.value))
  14. ui.input('Number input', on_change=lambda e: output.set_text(e.value), type='number')
  15. with ui.column():
  16. ui.radio(['A', 'B', 'C'], on_change=lambda e: output.set_text(e.value))
  17. ui.select(['1', '2', '3'], on_change=lambda e: output.set_text(e.value))
  18. with ui.row():
  19. ui.label('Output:')
  20. output = ui.label()
  21. with ui.card():
  22. ui.label('Timer', 'h5')
  23. time = ui.label()
  24. ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
  25. with ui.card():
  26. ui.label('Matplotlib', 'h5')
  27. with ui.plot(close=False) as plot:
  28. plt.title('Some plot')
  29. plt.plot(range(10), [x**2 for x in range(10)])
  30. def update_plot():
  31. plt.title('Some plot with a second curve')
  32. plt.plot(range(10), [100 - x**2 for x in range(10)])
  33. plot.update()
  34. ui.timer(3.0, update_plot, once=True)
  35. ui.run()