Преглед изворни кода

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 ..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()