Переглянути джерело

add awaitable ui.button.clicked()

Rodja Trappe 2 роки тому
батько
коміт
e9c23a60cd
1 змінених файлів з 7 додано та 0 видалено
  1. 7 0
      nicegui/elements/button.py

+ 7 - 0
nicegui/elements/button.py

@@ -1,3 +1,4 @@
+import asyncio
 from typing import Callable, Optional
 from typing import Callable, Optional
 
 
 from ..colors import set_background_color
 from ..colors import set_background_color
@@ -34,3 +35,9 @@ class Button(TextElement, DisableableElement):
 
 
     def _text_to_model_text(self, text: str) -> None:
     def _text_to_model_text(self, text: str) -> None:
         self._props['label'] = text
         self._props['label'] = text
+
+    async def clicked(self):
+        event = asyncio.Event()
+        self.on('click', event.set)
+        await self.client.connected()
+        await event.wait()