فهرست منبع

fix self-reference and improve group demo

Falko Schindler 4 سال پیش
والد
کامیت
52eabb4b0d
2فایلهای تغییر یافته به همراه7 افزوده شده و 5 حذف شده
  1. 1 1
      elements.py
  2. 6 4
      main.py

+ 1 - 1
elements.py

@@ -14,7 +14,7 @@ class Group:
 
         b = jp.Button(text=text, a=self.view, classes='p-2 w-48 bg-blue-700 text-white text-center')
         if on_click is not None:
-            b.on('click', handle_exceptions(provide_sender(on_click, self)))
+            b.on('click', handle_exceptions(provide_sender(on_click, b)))
         return b
 
     @contextmanager

+ 6 - 4
main.py

@@ -5,10 +5,12 @@ from datetime import datetime
 ui.label('Hello, Nice GUI!')
 
 with ui.row() as row:
-    row.button('BUTTON', on_click=lambda: row.label('Nice!'))
-    with row.column() as column:
-        column.button('BUTTON2')
-        column.label("LABEL")
+    with row.column() as left:
+        left.label('Add an element:')
+        left.button('Button 1', on_click=lambda: left.label('Nice!'))
+    with row.column() as right:
+        right.label("Update itself:")
+        right.button('Button 2', on_click=lambda b: setattr(b, 'text', b.text + ' :)'))
 
 with ui.plot():
     plt.title('Some plot')