Nested screenmanager

93 views
Skip to first unread message

Sam Peek

unread,
Mar 17, 2019, 10:50:13 AM3/17/19
to Kivy users support
class LoginScreen(Screen):

def goto_Mainscr(self):
self.current="Mainscr"

class MainScreen(Screen):
pass
class ScanScreen(Screen):
pass
class InventoryScreen(Screen):
pass
class ItemsScreen(Screen):
pass
class LogsScreen(Screen):
pass
class AlertsScreen(Screen):
pass
class HelpScreen(Screen):
pass


class MainManager(FloatLayout):

def __init__(self, **kwargs):
super(MainManager, self).__init__(**kwargs)


class Invtest3App(App):
def build(self):
return MainManager()


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

KV file:

<MainManager>:
    orientation: 'vertical'
    name: "mainm"
    id: mm
    ScreenManager:
        id: mainsm
        LoginScreen:
        MainScreen:

<LoginScreen>:
    name: "Loginscr"
    id: loginscr

    Button:
        name: "loginButton"
        text: "Login"
        background_color: 0,0,0,0
        pos_hint: {'x': 1.0/6.0, 'y': 0}
        size_hint: 1.0/6.0, 1
        on_press: root.goto_Mainscr()

<MainScreen>:
    name: "Mainscr"
    FloatLayout:
        pos_hint: {'top': 1}
        size_hint: 1, 0.1
        Button:
            name: "scanButton"
            text: "Scan"
            pos_hint: {'x': 0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Scan"
        Button:
            name: "inventoryButton"
            text: "Inventory"
            pos_hint: {'x': 1.0/6.0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Inventory"
        Button:
            name: "itemsButton"
            text: "Items"
            pos_hint: {'x': 2.0/6.0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Items"
        Button:
            name: "logsButton"
            text: "Logs"
            pos_hint: {'x': 3.0/6.0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Logs"
        Button:
            name: "alertsButton"
            text: "Alerts"
            pos_hint: {'x': 4.0/6.0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Alerts"
        Button:
            name: "helpButton"
            text: "Help"
            pos_hint: {'x': 5.0/6.0, 'y': 0}
            size_hint: 1.0/6.0, 1
            on_press: root.ids.sm.current = "Help"
    FloatLayout:
        ScreenManager:
            id: sm
            pos_hint: {'top': 0.9}
            size_hint: 1, 0.9
            ScanScreen:
            InventoryScreen:
            ItemsScreen:
            LogsScreen:
            AlertsScreen:
            HelpScreen:


Hi there,

I am working on an application and was wondering if it is possible to have a ScreenManager within a ScreenManager. The reason for this would be to have a login page using the full screen, and then screens that all use a navigation bar.

The code above tries to reflect this, could you please let me know wether this is possible and the best approach in kv AND python files together.

Many thanks.

Gabriel Pettier

unread,
Mar 17, 2019, 1:35:07 PM3/17/19
to kivy-...@googlegroups.com
Yes, this should work, and yes, it's a valid way to do it.

You might want to give an id to your MainScreen in MainManager, to be
able to do app.root.ids.mainmanager.ids.sm.current to get/set the
current screen.

Another if you don't want to nest ScreenManagers would be to have the
bars in all the screens, but just make them invisible (or move outside
of the screen) when in the LoginScreen (using a condition on self.name
could be a way).

But this way is fine, really.
>--
>You received this message because you are subscribed to the Google Groups "Kivy users support" group.
>To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
>To post to this group, send email to kivy-...@googlegroups.com.
>Visit this group at https://groups.google.com/group/kivy-users.
>To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/aafb3c68-21b5-4d46-be59-cd5fce104cae%40googlegroups.com.
>For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages