浏览代码

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