RadioTabs

Introduction

RadioTabs is a graphical user interface tool in Supervisely that allows users to group related widgets into tabs and switch between them using radio buttons. This feature is particularly useful for organizing and presenting complex interfaces with multiple settings and options. RadioTabs offers a simple and intuitive interface for users to quickly navigate between different tabs and access the desired widgets.

Function signature

RadioTabs(
    titles=["Info tab", "Success tab"],
    contents=[
        Text("Info text", status="info"),
        Text("Success text", status="success")
    ],
    descriptions=None,
    widget_id=None,
)

Parameters

ParametersTypeDescription

titles

List[str]

List of the tabs titles

contents

List[Widget]

List of tabs content

descriptions

List[str]

List of tabs descriptions

widget_id

str

ID of the widget

titles

Determine list of the tabs titles.

type: List[str]

contents

Determine list of the tabs content.

type: List[Widget]

tabs = RadioTabs(
    titles=["Info tab", "Success tab"],
    contents=[
        Text("Info text", status="info"),
        Text("Success text", status="success")
    ]
)

descriptions

Determine list of tabs descriptions.

type: List[str]

default value: None

tabs = RadioTabs(
    titles=["Info tab", "Success tab"],
    contents=[
        Text("Info text", status="info"),
        Text("Success text", status="success")
    ],
    descriptions=[
        "Tab with info text",
        "Tab with success text"
    ]
)

widget_id

ID of the widget.

type: str

default value: None

Methods and attributes

Attributes and MethodsDescription

set_active_tab(value: str)

Set active tab by title.

get_active_tab()

Return active tab title.

@value_changed

Decorator function handled when RadioTabs value is changed.

Mini App Example

You can find this example in our Github repository:

ui-widgets-demos/layouts and containers/011_radio_tabs/src/main.py

Import libraries

import os

import supervisely as sly
from dotenv import load_dotenv
from supervisely.app.widgets import Card, Container, RadioTabs, Text

Init API client

First, we load environment variables with credentials and init API for communicating with Supervisely Instance:

load_dotenv("local.env")
load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api()

Initialize RadioTabs widgets

tabs = RadioTabs(
    titles=["Info tab", "Success tab", "Warning tab", "Error tab"],
    contents=[
        Text("Info text", status="info"),
        Text("Success text", status="success"),
        Text("Warning text", status="warning"),
        Text("Error text", status="error"),
    ],
    descriptions=[
        "Tab with info text",
        "Tab with success text",
        "Tab with warning text",
        "Tab with error text",
    ],
)

many_tabs = RadioTabs(
    titles=[f"{i + 1} tab" for i in range(10)],
    contents=[Text(f"{i + 1} text", status="info") for i in range(10)],
    descriptions=[f"Tab with {i + 1} text" for i in range(10)],
)

Initialize Text widget to change text on widget

text = Text("Opened tab: Info tab")

Create app layout

Prepare a layout for app using Card widget with the content parameter and place widget that we've just created in the Container widget.

card = Card(
    title="Radio tabs",
    content=Container([tabs, text]),
)
card_many_tabs = Card(
    "Many radio tabs",
    content=many_tabs,
)

layout = Container(widgets=[card, card_many_tabs])

Create app using layout

Create an app object with layout parameter.

app = sly.Application(layout=layout)

Add functions to control widgets from python code

@tabs.value_changed
def show_opened_tab(value):
    text.text = f"Opened tab: {value}"

Last updated