Browse Source

add awaitable ui.button.clicked()

Rodja Trappe 2 years ago
parent
commit
e9c23a60cd
1 changed files with 7 additions and 0 deletions
  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 ..colors import set_background_color
@@ -34,3 +35,9 @@ class Button(TextElement, DisableableElement):
 
     def _text_to_model_text(self, text: str) -> None:
         self._props['label'] = text
+
+    async def clicked(self):
+        event = asyncio.Event()
+        self.on('click', event.set)
+        await self.client.connected()
+        await event.wait()