File size: 2,070 Bytes
ef835f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import gradio as gr

with gr.Blocks() as demo:
    with gr.Row():
        def change_to_tab_two():
            return gr.Tabs(selected=2) #This will navigate

        with gr.Tabs() as tabs:
            with gr.Tab(id=1, label="Tab 1", visible=True, interactive=True) as tab_one:
                tab_one_tbox = gr.Textbox(label="Tab One Textbox")
                tab_one_btn = gr.Button(value="Change Tab (shouldn't navigate)")
            with gr.Tab(id=2, label="Tab 2", visible=True, interactive=False) as tab_two:
                tab_two_tbox = gr.Textbox(label="Tab Two Textbox")
                tab_one_btn.click(fn=change_to_tab_two,inputs=None, outputs=[tabs])  # This does navigate

    with gr.Row():
        def change_to_tab_two():
            return gr.Tabs(selected=2), gr.Tab(label="New tab two label") #This won't navigate

        with gr.Tabs() as tabs:
            with gr.Tab(id=1, label="Tab 1", visible=True, interactive=True) as tab_one:
                tab_one_tbox = gr.Textbox(label="Tab One Textbox")
                tab_one_btn = gr.Button(value="Change Tab (should navigate)")
            with gr.Tab(id=2, label="Tab 2", visible=True, interactive=True) as tab_two:
                tab_two_tbox = gr.Textbox(label="Tab Two Textbox")
                tab_one_btn.click(fn=change_to_tab_two, inputs=None, outputs=[tabs, tab_two]) 

    with gr.Row():
        def change_to_tab_two():
            return gr.Tabs(selected=2), gr.Textbox(label="Textbox two new label")

        with gr.Tabs() as tabs:
            with gr.Tab(id=1, label="Tab 1", visible=True, interactive=True) as tab_one:
                tab_one_tbox = gr.Textbox(label="Tab One Textbox")
                tab_one_btn = gr.Button(value="Change Tab (should navigate)")
            with gr.Tab(id=2, label="Tab 2", visible=True, interactive=True) as tab_two:
                tab_two_tbox = gr.Textbox(label="Tab Two Textbox",interactive=False)
                tab_one_btn.click(fn=change_to_tab_two, inputs=None, outputs=[tabs, tab_two_tbox]) #This doesn't navigate

demo.launch()