{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 菜单\n", "\n", "基于 Quasar 的 [QMenu 组件](https://quasar.dev/vue-components/menu)创建一个菜单。菜单应该放置在它应该显示的元素内。\n", "\n", "`value`:菜单是否已经打开(默认:`False`)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.row().classes('w-full items-center'):\n", " result = ui.label().classes('mr-auto')\n", " with ui.button(icon='menu'):\n", " with ui.menu() as menu:\n", " ui.menu_item('Menu item 1', lambda: result.set_text('Selected item 1'))\n", " ui.menu_item('Menu item 2', lambda: result.set_text('Selected item 2'))\n", " ui.menu_item('Menu item 3 (keep open)',\n", " lambda: result.set_text('Selected item 3'), auto_close=False)\n", " ui.separator()\n", " ui.menu_item('Close', on_click=menu.close)\n", "\n", "# ui.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 上下文菜单\n", "\n", "基于 Quasar 的 [QMenu 组件](https://quasar.dev/vue-components/menu)创建一个上下文菜单。上下文菜单应放置在它应该显示的元素内。当用户右键单击元素时,它会自动打开,并出现在鼠标位置。" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from nicegui import ui\n", "\n", "with ui.image('https://picsum.photos/id/377/640/360'):\n", " with ui.context_menu():\n", " ui.menu_item('Flip horizontally')\n", " ui.menu_item('Flip vertically')\n", " ui.separator()\n", " ui.menu_item('Reset')\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 }