如何使用 TabbedPanels 更改 Kivy 选项卡的背景颜色?

How do you change the background color of Kivy tabs with TabbedPanels?

我有下面的代码,我似乎无法弄清楚如何更改 TabbedPanel 元素中选项卡的背景颜色,假设我希望它们是红色的。此外,当 do_default_tab 设置为 false 时,您将如何更改“默认”选项卡?假设我希望 Tab 3 在应用程序启动时首先打开。我一直在搜索,但似乎找不到任何有用的东西...

我将如何完成这两件事?

import kivy
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.widget import Widget


Builder.load_string(
    """
<GameScreen>:
    TabbedPanel:
        do_default_tab: False
        size: root.width, root.height

        TabbedPanelItem:
            text: 'Tab 1'
            Label:
                text: 'Screen 1'
        TabbedPanelItem:
            text: 'Tab 2'
            Label:
                text: 'Screen 2'
        TabbedPanelItem:
            text: 'Tab 3'
            Label:
                text: 'Screen 3'
"""
)


class GameScreen(Widget):
    pass


class MyApp(App):
    def build(self):
        self.title = 'Test App'
        self.icon = 'return_home/media/icons/test.ico'
        return GameScreen()


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

要更改颜色,请添加 background_color 以预定义状态,使用 state:

        TabbedPanelItem:
            id: tb1
            state: 'down'
            text: self.state
            background_color: "#30ff00"
            Label:
                text: 'Screen 1'