{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 工具提示\n", "\n", "这个元素基于 Quasar 的 [QTooltip 组件](https://quasar.dev/vue-components/tooltip)。它可以放置在另一个元素内,以在悬停时显示额外信息。\n", "\n", "除了将字符串作为第一个参数传递外,您还可以在工具提示内嵌套其他元素。\n", "\n", "`text`:工具提示的内容(默认为 `''`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.button(icon='thumb_up'):\n", " ui.tooltip('I like this').classes('bg-green')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 工具提示方法\n", "\n", "除了将工具提示元素嵌套在另一个元素内,您也可以使用工具提示方法。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from nicegui import ui\n", "\n", "ui.label('Tooltips...').tooltip('...are shown on mouse over')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 工具提示中的HTML\n", "\n", "您可以通过嵌套一个 `ui.html` 元素在工具提示中使用 HTML。" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.label('HTML...'):\n", " with ui.tooltip():\n", " ui.html('b, em, u, s')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 工具提示中的其他内容\n", "\n", "您可以在工具提示中使用 HTML。" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.label('Mountains...'):\n", " with ui.tooltip().classes('bg-transparent'):\n", " ui.image('https://picsum.photos/id/377/640/360').classes('w-64')\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## HTML 和 Markdown 上的工具提示\n", "\n", "一些元素,如 `ui.html` 和 `ui.markdown`,不支持嵌套元素。在这种情况下,您可以将此类元素嵌套在一个带有工具提示的容器元素内。" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.element().tooltip('...with a tooltip!'):\n", " ui.html('This is HTML...')\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 }