简体   繁体   中英

Windwomanager with TappedPanels

main.py:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.tabbedpanel import TabbedPanel




class Test(TabbedPanel):
    pass

class MainWindow(Screen):
    pass


class SecondWindow(Screen):
    pass


class WindowManager(ScreenManager):
    pass



kv = Builder.load_file("settings.kv")


class MyMainApp(App):
    def build(self):
        return kv


if __name__ == "__main__":
    MyMainApp().run()

settings.kv:

WindowManager:
    MainWindow:
    SecondWindow:
    Test:


<MainWindow>:
    name: "main"

    GridLayout:
        cols:2


        Button:
            text: "New Order"
            on_release:
                app.root.current = "tabs"
                root.manager.transition.direction = "left"


        Button:
            text: "Basket"
            on_release:
                app.root.current = "second"
                root.manager.transition.direction = "left"


<SecondWindow>:
    name: "second"

    Button:
        text: "Go Back"
        on_release:
            app.root.current = "main"
            root.manager.transition.direction = "right"


<Test>:
    name: "test"
    size_hint: .5, .5
    pos_hint: {'center_x': .5, 'center_y': .5}
    do_default_tab: False

    TabbedPanelItem:
        text: 'first tab'
        Label:
            text: 'First tab content area'
    TabbedPanelItem:
        text: 'tab2'
        BoxLayout:
            Label:
                text: 'Second tab content area'
            Button:
                text: 'Button that does nothing'
    TabbedPanelItem:
        text: 'tab3'
        RstDocument:
            text:
                '\\n'.join(("Hello world", "-----------",
                "You are in the third tab."))

I want a transition that starts with a button press that leads to a tabbed overlay, However the screenmanager doesnt accept the use of tabbedpanel

 kivy.uix.screenmanager.ScreenManagerException: ScreenManager accepts only Screen widget.

How can I achieve this effect, I am new to kivy. I want one button press to go to a another normal screen while the other one to open a tabbed screen,

只需将您的TabbedPanel放在Screen

Good day. Use your screen manager to switch between each screen . The screen then contains your unique layout of whatever you placed in it. That could include a screen with tabs.

Just add a TabblePanel to one of your Screens.

<BlaBlaScreen>:
    name: 'BlaBla'
    TabbedPanel:
        do_default_tab: False
        TabbedPanelItem:
            text: "something"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM