Kivy - TabbedPanel headers slight offset

2019-09-13 07:14发布

问题:

I'm using the TabbedPanel (with the default tab_pos: "top_left") but the headers (as one can see in the docs) are slighty not on the left. It's like there is a small padding-left of 1px which is applied. I can't figure out how to configure that. Any insights? Thanks!

回答1:

A hacky, non-pretty solution:

from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.lang import Builder

Builder.load_string('''
<MyWidget>:
    TabbedPanelItem:
        text: 'tab1'
    TabbedPanelItem:
        text: 'tab2'
''')


class MyWidget(TabbedPanel):
    def __init__(self, **kwargs):
        super(MyWidget, self).__init__(**kwargs)
        self._tab_layout.padding = [0, 0, 0, 0]


class MyApp(App):
    def build(self):
        return MyWidget()


if __name__ == '__main__':
    MyApp().run()