How can i use tabs as an input?

Iā€™m creating some tabs and when i click a button i want to use the name of the tabs as an input for a function. How does it work? Thank you very much!

My way of creating tabs would be for example this, with blocks:

with gr.Tabs() as tabs:
                with gr.TabItem("test1"):
                    bt_test1 = gr.Button('test1')
                with gr.TabItem("test2"):   
                    bt_test2 = gr.Button('test2')

You can use the select() event listener that TabItem (which also has the alias Tab) supports:

import gradio as gr

with gr.Blocks() as demo:
    with gr.Tabs():
        with gr.Tab("hi") as hi:
            pass
        with gr.Tab("hello") as hello:
            pass
        
    output = gr.Textbox()
    hi.select(lambda :"hi", None, output)
    hello.select(lambda :"hello", None, output) 
    
demo.launch()
1 Like