---
tags: [gradio-custom-component, SideBar]
title: gradio_topbar
short_description: A TopBar for Gradio Interface
colorFrom: blue
colorTo: yellow
sdk: gradio
pinned: false
app_file: space.py
---
# `gradio_topbar`
<img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
A TopBar for Gradio Interface
## Installation
```bash
pip install gradio_topbar
```
## Usage
```python
# demo/app.py
import gradio as gr
import time
from gradio_topbar import TopBar
def chat_response(message, history):
history = history or ""
history += f"You: {message}\n"
time.sleep(1) # Simulate thinking
history += f"Bot: Thanks for the message! You said: '{message}'\n"
return history, ""
def update_label(value):
return f"Current temperature is: {value}"
with gr.Blocks(theme=gr.themes.Ocean(), title="Full Layout Demo") as demo:
gr.Markdown(
"""
# TopBar Demo
This demo shows the `TopBar` with `width="50%"` and `bring_to_front=True`.
Notice how the bar is now horizontally centered and no longer full-width.
"""
)
with TopBar(open=True, height=180, width="50%", bring_to_front=True):
with gr.Row():
message_box = gr.Textbox(
show_label=False,
placeholder="Type your message here...",
elem_id="message-input",
scale=7
)
send_button = gr.Button("Send", variant="primary", scale=1)
with gr.Row():
gr.Button("Upload File")
gr.Button("Record Audio")
gr.ClearButton([message_box])
with gr.Row(equal_height=True):
with gr.Column(scale=3):
gr.Markdown("### 🤖 Chat Interface")
chatbot_display = gr.Textbox(
label="Chat History",
lines=25,
interactive=False
)
send_button.click(
fn=chat_response,
inputs=[message_box, chatbot_display],
outputs=[chatbot_display, message_box]
)
message_box.submit(
fn=chat_response,
inputs=[message_box, chatbot_display],
outputs=[chatbot_display, message_box]
)
if __name__ == "__main__":
demo.launch(debug=True)
```
## `TopBar`
### Initialization
<table>
<thead>
<tr>
<th align="left">name</th>
<th align="left" style="width: 25%;">type</th>
<th align="left">default</th>
<th align="left">description</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left"><code>label</code></td>
<td align="left" style="width: 25%;">
```python
str | gradio.i18n.I18nData | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">name of the top bar. Not displayed to the user.</td>
</tr>
<tr>
<td align="left"><code>open</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">if True, top bar is open by default.</td>
</tr>
<tr>
<td align="left"><code>visible</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">If False, the component will be hidden.</td>
</tr>
<tr>
<td align="left"><code>elem_id</code></td>
<td align="left" style="width: 25%;">
```python
str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
</tr>
<tr>
<td align="left"><code>elem_classes</code></td>
<td align="left" style="width: 25%;">
```python
list[str] | str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles.</td>
</tr>
<tr>
<td align="left"><code>render</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>True</code></td>
<td align="left">If False, this layout will not be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>
</tr>
<tr>
<td align="left"><code>height</code></td>
<td align="left" style="width: 25%;">
```python
int | str
```
</td>
<td align="left"><code>320</code></td>
<td align="left">The height of the top bar, specified in pixels if a number is passed, or in CSS units if a string is passed.</td>
</tr>
<tr>
<td align="left"><code>width</code></td>
<td align="left" style="width: 25%;">
```python
int | str
```
</td>
<td align="left"><code>"100%"</code></td>
<td align="left">The width of the top bar, specified in pixels if a number is passed, or in CSS units (like "80%") if a string is passed. The bar will be horizontally centered.</td>
</tr>
<tr>
<td align="left"><code>bring_to_front</code></td>
<td align="left" style="width: 25%;">
```python
bool
```
</td>
<td align="left"><code>False</code></td>
<td align="left">If True, the TopBar will be rendered on top of all other elements with a higher z-index. Defaults to False.</td>
</tr>
<tr>
<td align="left"><code>key</code></td>
<td align="left" style="width: 25%;">
```python
int | str | tuple[int | str, Ellipsis] | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.</td>
</tr>
<tr>
<td align="left"><code>preserved_by_key</code></td>
<td align="left" style="width: 25%;">
```python
list[str] | str | None
```
</td>
<td align="left"><code>None</code></td>
<td align="left">A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.</td>
</tr>
</tbody></table>
### Events
| name | description |
|:-----|:------------|
| `expand` | This listener is triggered when the TopBar is expanded. |
| `collapse` | This listener is triggered when the TopBar is collapsed. |
Raw data
{
"_id": null,
"home_page": null,
"name": "gradio-topbar",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "gradio-custom-component, gradio-template-Sidebar",
"author": null,
"author_email": "Eliseu Silva <elismasilva@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/0c/3e/260b96ed6e97faebe248529fe7b1b98c33184fbf048f80bdd7b044fed016/gradio_topbar-0.0.1.tar.gz",
"platform": null,
"description": "---\ntags: [gradio-custom-component, SideBar]\ntitle: gradio_topbar\nshort_description: A TopBar for Gradio Interface\ncolorFrom: blue\ncolorTo: yellow\nsdk: gradio\npinned: false\napp_file: space.py\n---\n\n# `gradio_topbar`\n<img alt=\"Static Badge\" src=\"https://img.shields.io/badge/version%20-%200.0.1%20-%20orange\"> \n\nA TopBar for Gradio Interface\n\n## Installation\n\n```bash\npip install gradio_topbar\n```\n\n## Usage\n\n```python\n# demo/app.py\n\nimport gradio as gr\nimport time\nfrom gradio_topbar import TopBar\n\ndef chat_response(message, history):\n history = history or \"\"\n history += f\"You: {message}\\n\"\n time.sleep(1) # Simulate thinking\n history += f\"Bot: Thanks for the message! You said: '{message}'\\n\"\n return history, \"\"\n\ndef update_label(value):\n return f\"Current temperature is: {value}\"\n\nwith gr.Blocks(theme=gr.themes.Ocean(), title=\"Full Layout Demo\") as demo:\n gr.Markdown(\n \"\"\"\n # TopBar Demo\n This demo shows the `TopBar` with `width=\"50%\"` and `bring_to_front=True`.\n Notice how the bar is now horizontally centered and no longer full-width.\n \"\"\"\n )\n\n with TopBar(open=True, height=180, width=\"50%\", bring_to_front=True):\n with gr.Row():\n message_box = gr.Textbox(\n show_label=False,\n placeholder=\"Type your message here...\",\n elem_id=\"message-input\",\n scale=7\n )\n send_button = gr.Button(\"Send\", variant=\"primary\", scale=1)\n with gr.Row():\n gr.Button(\"Upload File\")\n gr.Button(\"Record Audio\")\n gr.ClearButton([message_box])\n\n with gr.Row(equal_height=True):\n with gr.Column(scale=3):\n gr.Markdown(\"### \ud83e\udd16 Chat Interface\")\n chatbot_display = gr.Textbox(\n label=\"Chat History\",\n lines=25,\n interactive=False\n )\n\n send_button.click(\n fn=chat_response,\n inputs=[message_box, chatbot_display],\n outputs=[chatbot_display, message_box]\n )\n message_box.submit(\n fn=chat_response,\n inputs=[message_box, chatbot_display],\n outputs=[chatbot_display, message_box]\n )\n\nif __name__ == \"__main__\":\n demo.launch(debug=True)\n```\n\n## `TopBar`\n\n### Initialization\n\n<table>\n<thead>\n<tr>\n<th align=\"left\">name</th>\n<th align=\"left\" style=\"width: 25%;\">type</th>\n<th align=\"left\">default</th>\n<th align=\"left\">description</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td align=\"left\"><code>label</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | gradio.i18n.I18nData | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">name of the top bar. Not displayed to the user.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>open</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">if True, top bar is open by default.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>visible</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">If False, the component will be hidden.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_id</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nstr | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>elem_classes</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">An optional string or list of strings that are assigned as the class of this component in the HTML DOM. Can be used for targeting CSS styles.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>render</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>True</code></td>\n<td align=\"left\">If False, this layout will not be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>height</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | str\n```\n\n</td>\n<td align=\"left\"><code>320</code></td>\n<td align=\"left\">The height of the top bar, specified in pixels if a number is passed, or in CSS units if a string is passed.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>width</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | str\n```\n\n</td>\n<td align=\"left\"><code>\"100%\"</code></td>\n<td align=\"left\">The width of the top bar, specified in pixels if a number is passed, or in CSS units (like \"80%\") if a string is passed. The bar will be horizontally centered.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>bring_to_front</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nbool\n```\n\n</td>\n<td align=\"left\"><code>False</code></td>\n<td align=\"left\">If True, the TopBar will be rendered on top of all other elements with a higher z-index. Defaults to False.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>key</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nint | str | tuple[int | str, Ellipsis] | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.</td>\n</tr>\n\n<tr>\n<td align=\"left\"><code>preserved_by_key</code></td>\n<td align=\"left\" style=\"width: 25%;\">\n\n```python\nlist[str] | str | None\n```\n\n</td>\n<td align=\"left\"><code>None</code></td>\n<td align=\"left\">A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.</td>\n</tr>\n</tbody></table>\n\n\n### Events\n\n| name | description |\n|:-----|:------------|\n| `expand` | This listener is triggered when the TopBar is expanded. |\n| `collapse` | This listener is triggered when the TopBar is collapsed. |\n\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A TopBar for Gradio Interface",
"version": "0.0.1",
"project_urls": null,
"split_keywords": [
"gradio-custom-component",
" gradio-template-sidebar"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fdf03b40f08ce460d5793dab26eb15afeaf94bffaf7c05f215dd696302cc40c6",
"md5": "4c52bed9e196d93f2c0077e0db502d16",
"sha256": "760126e263d74bdb8d94919979dc771eef7cdaddccb955fe904bdaf0688d3b41"
},
"downloads": -1,
"filename": "gradio_topbar-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4c52bed9e196d93f2c0077e0db502d16",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 82474,
"upload_time": "2025-08-13T03:03:25",
"upload_time_iso_8601": "2025-08-13T03:03:25.748472Z",
"url": "https://files.pythonhosted.org/packages/fd/f0/3b40f08ce460d5793dab26eb15afeaf94bffaf7c05f215dd696302cc40c6/gradio_topbar-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0c3e260b96ed6e97faebe248529fe7b1b98c33184fbf048f80bdd7b044fed016",
"md5": "379fcfb62420ce5fda8939b8969f9ff1",
"sha256": "b908ec33c4d902120c5803316b0f3325ae971bd3e770feea93729e0ac12ac3de"
},
"downloads": -1,
"filename": "gradio_topbar-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "379fcfb62420ce5fda8939b8969f9ff1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 144391,
"upload_time": "2025-08-13T03:03:27",
"upload_time_iso_8601": "2025-08-13T03:03:27.163464Z",
"url": "https://files.pythonhosted.org/packages/0c/3e/260b96ed6e97faebe248529fe7b1b98c33184fbf048f80bdd7b044fed016/gradio_topbar-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-13 03:03:27",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "gradio-topbar"
}