main.py 978 B

12345678910111213141516171819202122232425262728293031
  1. from nice_gui import ui
  2. import matplotlib.pyplot as plt
  3. from datetime import datetime
  4. ui.label('Hello, Nice GUI!')
  5. with ui.row() as row:
  6. with row.column() as left:
  7. left.label('Add an element:')
  8. left.button('Button 1', on_click=lambda: left.label('Nice!'))
  9. with row.column() as right:
  10. right.label("Update itself:")
  11. right.button('Button 2', on_click=lambda e: setattr(e.sender, 'text', e.sender.text + ' :)'))
  12. ui.select(['one', 'two', 'three'], 'one', on_change=lambda e: output.label(e.value))
  13. with ui.row() as output:
  14. pass
  15. with ui.card() as card:
  16. with card.plot():
  17. plt.title('Some plot')
  18. plt.plot(range(10), [x**2 for x in range(10)])
  19. with card.row() as row:
  20. row.checkbox('Let''s check...', on_change=lambda e: row.label('Check!' if e.checked else 'Uncheck.'))
  21. time = ui.label('Time:')
  22. def update_time():
  23. time.text = f'Time: {datetime.now().strftime("%H:%M:%S")}'
  24. ui.timer(1.0, update_time)