{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 异步事件处理器\n", "\n", "大多数元素也支持异步事件处理器。\n", "\n", "注意:您还可以将 `functools.partial` 传递给 `on_click` 属性,以包装带参数的异步函数。" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import asyncio\n", "from nicegui import ui\n", "\n", "async def async_task():\n", " ui.notify('Asynchronous task started')\n", " await asyncio.sleep(5)\n", " ui.notify('Asynchronous task finished')\n", "\n", "ui.button('start async task', on_click=async_task)\n", "\n", "# ui.run()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "py311", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.7" } }, "nbformat": 4, "nbformat_minor": 2 }