0

I have TabbedPanelItem's that are dynamically built in Python code. See code below. I have 3 questions:

  1. how could I enable the first tab? No content is shown after start but only when a tab is clicked.
  2. how could I switch to a tab from the Python part?
  3. 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'
Bill Bridge
  • 821
  • 1
  • 9
  • 30

1 Answers1

0

1) default_tab - this one wants object, so get one either within kv with id, or <class>.ids.<tab id> so that you can use it in the property. Or even get it through <class>.children - the last item should be the first tab. Example:

TabbedPanel:
    default_tab: deflt

    TabbedPanelItem:
        text: '1'
        Button:

    TabbedPanelItem:
        text: '2'

    TabbedPanelItem:
        id: deflt
        text: '3'
        Label:
            text: 'the default one'

2) switch_to - a function that wants an object to which it should switch. Again do it with id or children

your_tab_panel.switch_to(<some id from kv or object>)

3) How to position text horizontally in vertical tabs?

Community
  • 1
  • 1
Peter Badida
  • 11,310
  • 10
  • 44
  • 90
  • 1
    Hi KeyWeeUsr, thanks for the answers. Re. the third question, I have decided to use images for the labels that are in origin 'rotated' 90 degrees clockwise. I have added this to the code above. – Bill Bridge Jun 15 '16 at 05:26