Bläddra i källkod

buttons with icons

Falko Schindler 4 år sedan
förälder
incheckning
691fb94918
2 ändrade filer med 16 tillägg och 5 borttagningar
  1. 5 3
      main.py
  2. 11 2
      nice_gui.py

+ 5 - 3
main.py

@@ -7,7 +7,7 @@ with ui.card():
     ui.label('Interactive elements', 'h5')
     ui.label('Interactive elements', 'h5')
     with ui.row():
     with ui.row():
         with ui.column():
         with ui.column():
-            ui.button('Click me!', on_click=lambda: output.set_text('Click'))
+            ui.button('Click me!', icon='touch_app', on_click=lambda: output.set_text('Click'))
             ui.checkbox('Check me!', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
             ui.checkbox('Check me!', on_change=lambda e: output.set_text('Checked' if e.value else 'Unchecked'))
             ui.switch('Switch me!', on_change=lambda e: output.set_text('Switched' if e.value else 'Unswitched'))
             ui.switch('Switch me!', on_change=lambda e: output.set_text('Switched' if e.value else 'Unswitched'))
             ui.slider(0, 100, on_change=lambda e: output.set_text(e.value))
             ui.slider(0, 100, on_change=lambda e: output.set_text(e.value))
@@ -22,8 +22,10 @@ with ui.card():
 
 
 with ui.card():
 with ui.card():
     ui.label('Timer', 'h5')
     ui.label('Timer', 'h5')
-    time = ui.label()
-    ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
+    with ui.row():
+        ui.icon('far fa-clock')
+        time = ui.label()
+        ui.timer(0.1, lambda: time.set_text(datetime.now().strftime("%X")))
 
 
 with ui.card():
 with ui.card():
     ui.label('Matplotlib', 'h5')
     ui.label('Matplotlib', 'h5')

+ 11 - 2
nice_gui.py

@@ -65,9 +65,18 @@ class Ui(Starlette):
         view = jp.Div(text=text, classes=classes)
         view = jp.Div(text=text, classes=classes)
         return Element(view)
         return Element(view)
 
 
-    def button(self, text, on_click=None):
+    def icon(self, name):
 
 
-        view = jp.QBtn(text=text, color='primary')
+        view = jp.QIcon(name=name, classes='q-pt-xs')
+        return Element(view)
+
+    def button(self, text, icon=None, icon_right=None, on_click=None):
+
+        view = jp.QBtn(label=text, color='primary')
+        if icon is not None:
+            view.icon = icon
+        if icon_right is not None:
+            view.icon_right = icon_right
         if on_click is not None:
         if on_click is not None:
             view.on('click', handle_exceptions(provide_arguments(on_click)))
             view.on('click', handle_exceptions(provide_arguments(on_click)))
         return Element(view)
         return Element(view)