Falko Schindler 4 年之前
父節點
當前提交
5c1917eb7c
共有 2 個文件被更改,包括 13 次插入0 次删除
  1. 10 0
      elements.py
  2. 3 0
      main.py

+ 10 - 0
elements.py

@@ -17,6 +17,16 @@ class Group:
             b.on('click', handle_exceptions(provide_sender(on_click, b)))
             b.on('click', handle_exceptions(provide_sender(on_click, b)))
         return b
         return b
 
 
+    def checkbox(self, text=None, on_change=None) -> jp.Input:
+
+        d = jp.Div(a=self.view, classes='flex gap-4')
+        c = jp.Input(a=d, type='checkbox', classes='form-checkbox mt-1 ml-4')
+        if text is not None:
+            jp.Div(text=text, a=d)
+        if on_change is not None:
+            c.on('change', handle_exceptions(provide_sender(on_change, c)))
+        return c
+
     @contextmanager
     @contextmanager
     def plot(self):
     def plot(self):
 
 

+ 3 - 0
main.py

@@ -12,6 +12,9 @@ with ui.row() as row:
         right.label("Update itself:")
         right.label("Update itself:")
         right.button('Button 2', on_click=lambda b: setattr(b, 'text', b.text + ' :)'))
         right.button('Button 2', on_click=lambda b: setattr(b, 'text', b.text + ' :)'))
 
 
+with ui.row() as row:
+    row.checkbox('Let''s check...', on_change=lambda: row.label('Check!'))
+
 with ui.plot():
 with ui.plot():
     plt.title('Some plot')
     plt.title('Some plot')
     plt.plot(range(10), [x**2 for x in range(10)])
     plt.plot(range(10), [x**2 for x in range(10)])