Skip to main content

Creating tabs & sections

In some cases, the parametrization becomes quite big which requires a more structured layout. This can be achieved by making use of a Tab and Section, which represent a tab and collapsible section in the interface respectively.

A 2-layered structure using Tab objects looks like this:

from viktor.parametrization import ViktorParametrization, TextField, NumberField, Tab


class Parametrization(ViktorParametrization):
tab_1 = Tab('Tab 1')
tab_1.input_1 = TextField('This is a text field')
tab_1.input_2 = NumberField('This is a number field')

tab_2 = Tab('Tab 2')
tab_2.input_1 = TextField('Text field in Tab 1')
tab_2.input_2 = NumberField('Number field in Tab 1')

Parametrization with tabs, no sections

Using Section objects results in the following:

from viktor.parametrization import ViktorParametrization, TextField, NumberField, Section


class Parametrization(ViktorParametrization):
section_1 = Section('Section 1')
section_1.input_1 = TextField('This is a text field')
section_1.input_2 = NumberField('This is a number field')

section_2 = Section('Section 2')
section_2.input_1 = TextField('Text field in Section 1')
section_2.input_2 = NumberField('Number field in Section 1')

Parametrization with sections, no tabs

A parametrization with a maximum depth of 3 layers consists of Tab, Section, and Field objects:

from viktor.parametrization import ViktorParametrization, TextField, NumberField, Tab, Section


class Parametrization(ViktorParametrization):
tab_1 = Tab('Tab 1')
tab_1.section_1 = Section('Section 1')
tab_1.section_1.input_1 = TextField('This is a text field')
tab_1.section_1.input_2 = NumberField('This is a number field')

tab_1.section_2 = Section('Section 2')
...

tab_2 = Tab('Tab 2')
...

Parametrization with sections and tabs

Hide a Tab / Section

New in v14.7.0

Hiding a Tab or Section can be done in a similar way as hiding a field, by setting the visible argument:

Tab("Tab 2", visible=Lookup("tab_1.param_x"))

or using a callback function:

Tab("Tab 2", visible=get_visible)