{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import panel as pn\n", "pn.extension()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``Button`` widget allows triggering events when the button is clicked. In addition to a value parameter, which will toggle from `False` to `True` while the click event is being processed an additional ``clicks`` parameter that can be watched to subscribe to click events.\n", "\n", "For more information about listening to widget events and laying out widgets refer to the [widgets user guide](../../user_guide/Widgets.ipynb). Alternatively you can learn how to build GUIs by declaring parameters independently of any specific widgets in the [param user guide](../../user_guide/Param.ipynb). To express interactivity entirely using Javascript without the need for a Python server take a look at the [links user guide](../../user_guide/Param.ipynb).\n", "\n", "#### Parameters:\n", "\n", "For layout and styling related parameters see the [customization user guide](../../user_guide/Customization.ipynb).\n", "\n", "##### Core\n", "\n", "* **``clicks``** (int): Number of clicks (can be listened to)\n", "* **``value``** (boolean): Toggles from `False` to `True` while the event is being processed.\n", "\n", "##### Display\n", "\n", "* **``button_type``** (str): A button theme; should be one of ``'default'`` (white), ``'primary'`` (blue), ``'success'`` (green), ``'info'`` (yellow), ``'light'`` (light), or ``'danger'`` (red)\n", "* **``disabled``** (boolean): Whether the widget is editable\n", "* **``name``** (str): The title of the widget\n", "\n", "___" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "button = pn.widgets.Button(name='Click me', button_type='primary')\n", "button" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``clicks`` parameter will report the number of times the button has been pressed:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "button.clicks" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``on_click`` method can trigger function when button is clicked:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "text = pn.widgets.TextInput(value='Ready')\n", "\n", "def b(event):\n", " text.value = 'Clicked {0} times'.format(button.clicks)\n", " \n", "button.on_click(b)\n", "pn.Row(button, text)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``Button`` name string may contain Unicode characters, providing a convenient way to define common graphical buttons:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "backward = pn.widgets.Button(name='\\u25c0', width=50)\n", "forward = pn.widgets.Button(name='\\u25b6', width=50)\n", "search = pn.widgets.Button(name='🔍', width=100)\n", "\n", "pn.Row(backward, forward, search)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The color of the button can be set by selecting one of the available button types:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Column(*(pn.widgets.Button(name=p, button_type=p) for p in pn.widgets.Button.param.button_type.objects))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Controls\n", "\n", "The `Button` widget exposes a number of options which can be changed from both Python and Javascript. Try out the effect of these parameters interactively:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "pn.Row(button.controls, button)" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }