I have TabbedPanelItem's that are dynamically built in Python code. See code below. I have 3 questions:
- how could I enable the first tab? No content is shown after start but only when a tab is clicked.
- how could I switch to a tab from the Python part?
- how could I rotate the text (i.e. the numbers) in the TabbedPanelItem so that it reads horizontally?
The Python code:
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import ObjectProperty
import string
class RootWidget(FloatLayout):
tab_panel = ObjectProperty(None)
tab_1 = ObjectProperty(None)
def init_root(self):
panel = self.ids.tab_panel
tpitem = string.Template('''
TabbedPanelItem:
id: '$tab_id'
background_normal: '$imgn'
background_down: '$imgd'
BoxLayout:
Label:
text: '$label_txt'
font_size: 14
color: 1,0,0,1
''')
for idx in range (5, 0, -1):
event = str(idx)
tab_id = 'tab_' + event
imgn = './images/tn-' + event + '.png'
imgd = './images/td-' + event + '.png'
label_txt = tab_id + " intentionally left blank"
next_tab = tpitem.substitute(vars())
tab = Builder.load_string(next_tab)
panel.add_widget(tab)
#self.tab_panel.switch_to(self.tab_1)
class addtabApp(App):
def build(self):
homeWin = RootWidget()
homeWin.init_root()
return homeWin
if __name__ == '__main__':
addtabApp().run()
The kv file:
<RootWidget>:
tab_panel:tab_panel
#tab_1:tab_1
TabbedPanel:
id: tab_panel
do_default_tab: False
tab_pos: 'left_top'