Falko Schindler 4 years ago
parent
commit
28a81b856d
2 changed files with 8 additions and 0 deletions
  1. 1 0
      main.py
  2. 7 0
      nice_gui.py

+ 1 - 0
main.py

@@ -21,6 +21,7 @@ with ui.card():
 with ui.card():
     ui.label('Interactive elements', 'h5')
     ui.button('Click me!', on_click=lambda: output.set_text('Click'))
+    ui.checkbox('Check me!', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
     output = ui.label()
 
 with ui.card():

+ 7 - 0
nice_gui.py

@@ -66,6 +66,13 @@ class Ui(Starlette):
             view.on('click', handle_exceptions(provide_arguments(on_click)))
         return Element(view)
 
+    def checkbox(self, text, on_change=None):
+
+        view = jp.QCheckbox(text=text)
+        if on_change is not None:
+            view.on('input', handle_exceptions(provide_arguments(on_change, 'value')))
+        return Element(view)
+
     @contextmanager
     def plot(self, close=True):