I am working on a Jupyter Notebook
in which I am creating a tab widget
in python using the following code:
import ipywidgets as widgets
tab_contents = ['P0', 'P1']
children = [widgets.Text(description=name) for name in tab_contents]
tab = widgets.Tab()
tab.children = children
for i in range(len(children)):
tab.set_title(i, str(i))
if tab.selected_index ==0:
vartest = 0
else:
vartest = 1
display(tab)
In a different cell, I check the value of vartest by calling it
vartest
The problem is that independently of the tab I have selected, vartest is always 0. What I want is that when I am in tab P0
(tab.selected_index ==0
), vartest should be 0, when I am in P1
(tab.selected_index ==1
) vartest should be 1.
What am I missing?
-- EDIT --