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
Copy RadioTabs (
titles = [ "Info tab" , "Success tab" ],
contents = [
Text ( "Info text" , status = "info" ),
Text ( "Success text" , status = "success" )
],
descriptions = None ,
widget_id = None ,
)
Parameters
Parameters Type Description List of tabs descriptions
titles
Determine list of the tabs titles.
type: List[str]
contents
Determine list of the tabs content.
type: List[Widget]
Copy 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
Copy 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 Methods Description set_active_tab(value: str)
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
Copy 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:
Copy load_dotenv ( "local.env" )
load_dotenv (os.path. expanduser ( "~/supervisely.env" ))
api = sly . Api ()
Initialize RadioTabs
widgets
Copy 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
Copy 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.
Copy 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.
Copy app = sly . Application (layout = layout)
Add functions to control widgets from python code
Copy @tabs . value_changed
def show_opened_tab ( value ):
text . text = f "Opened tab: { value } "