How to manage screens from a different layout












0















I am trying to have a set of buttons that controls what screen is displayed while still having the buttons displayed.



bobo.py



import kivy
kivy.require("1.9.0")

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout

class ButtSection(BoxLayout):
pass

class Welcome(Screen):
pass

class AccountOne(Screen):
pass

class AccountTwo(Screen):
pass

class ScreenManagement(ScreenManager):
pass

presentation = Builder.load_file("Bobo.kv")

class BoboApp(App):
def build(self):
return presentation

main = BoboApp()
main.run()


Bobo.kv



BoxLayout:
orientation: "horizontal"
BoxLayout:
ButtSection:
orientation: "vertical"
Button:
text: "Account One"
on_press: app.root.current = "a1"
Button:
text: "Account Two"
on_press: app.root.current = "a2"
Button:
text: "Account Three"
on_press: app.root.current = "a3"

ScreenManagement:
Welcome:
name: "wel"
Label:
text: "Welcome To Bobot"
AccountOne:
name: "a1"
Label:
text: "Page: Account One"
AccountTwo:
name: "a2"
Label:
text: "Page: Account One"


When I run the script, the welcome screen is the current screen. When I click a button, is does nothing even thought i included 'on_press: app.root.current = ''.










share|improve this question

























  • The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

    – John Anderson
    Jan 1 at 18:32











  • wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

    – B Food
    Jan 1 at 19:18











  • In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

    – John Anderson
    Jan 1 at 22:11
















0















I am trying to have a set of buttons that controls what screen is displayed while still having the buttons displayed.



bobo.py



import kivy
kivy.require("1.9.0")

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout

class ButtSection(BoxLayout):
pass

class Welcome(Screen):
pass

class AccountOne(Screen):
pass

class AccountTwo(Screen):
pass

class ScreenManagement(ScreenManager):
pass

presentation = Builder.load_file("Bobo.kv")

class BoboApp(App):
def build(self):
return presentation

main = BoboApp()
main.run()


Bobo.kv



BoxLayout:
orientation: "horizontal"
BoxLayout:
ButtSection:
orientation: "vertical"
Button:
text: "Account One"
on_press: app.root.current = "a1"
Button:
text: "Account Two"
on_press: app.root.current = "a2"
Button:
text: "Account Three"
on_press: app.root.current = "a3"

ScreenManagement:
Welcome:
name: "wel"
Label:
text: "Welcome To Bobot"
AccountOne:
name: "a1"
Label:
text: "Page: Account One"
AccountTwo:
name: "a2"
Label:
text: "Page: Account One"


When I run the script, the welcome screen is the current screen. When I click a button, is does nothing even thought i included 'on_press: app.root.current = ''.










share|improve this question

























  • The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

    – John Anderson
    Jan 1 at 18:32











  • wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

    – B Food
    Jan 1 at 19:18











  • In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

    – John Anderson
    Jan 1 at 22:11














0












0








0








I am trying to have a set of buttons that controls what screen is displayed while still having the buttons displayed.



bobo.py



import kivy
kivy.require("1.9.0")

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout

class ButtSection(BoxLayout):
pass

class Welcome(Screen):
pass

class AccountOne(Screen):
pass

class AccountTwo(Screen):
pass

class ScreenManagement(ScreenManager):
pass

presentation = Builder.load_file("Bobo.kv")

class BoboApp(App):
def build(self):
return presentation

main = BoboApp()
main.run()


Bobo.kv



BoxLayout:
orientation: "horizontal"
BoxLayout:
ButtSection:
orientation: "vertical"
Button:
text: "Account One"
on_press: app.root.current = "a1"
Button:
text: "Account Two"
on_press: app.root.current = "a2"
Button:
text: "Account Three"
on_press: app.root.current = "a3"

ScreenManagement:
Welcome:
name: "wel"
Label:
text: "Welcome To Bobot"
AccountOne:
name: "a1"
Label:
text: "Page: Account One"
AccountTwo:
name: "a2"
Label:
text: "Page: Account One"


When I run the script, the welcome screen is the current screen. When I click a button, is does nothing even thought i included 'on_press: app.root.current = ''.










share|improve this question
















I am trying to have a set of buttons that controls what screen is displayed while still having the buttons displayed.



bobo.py



import kivy
kivy.require("1.9.0")

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout

class ButtSection(BoxLayout):
pass

class Welcome(Screen):
pass

class AccountOne(Screen):
pass

class AccountTwo(Screen):
pass

class ScreenManagement(ScreenManager):
pass

presentation = Builder.load_file("Bobo.kv")

class BoboApp(App):
def build(self):
return presentation

main = BoboApp()
main.run()


Bobo.kv



BoxLayout:
orientation: "horizontal"
BoxLayout:
ButtSection:
orientation: "vertical"
Button:
text: "Account One"
on_press: app.root.current = "a1"
Button:
text: "Account Two"
on_press: app.root.current = "a2"
Button:
text: "Account Three"
on_press: app.root.current = "a3"

ScreenManagement:
Welcome:
name: "wel"
Label:
text: "Welcome To Bobot"
AccountOne:
name: "a1"
Label:
text: "Page: Account One"
AccountTwo:
name: "a2"
Label:
text: "Page: Account One"


When I run the script, the welcome screen is the current screen. When I click a button, is does nothing even thought i included 'on_press: app.root.current = ''.







python-3.x kivy






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 1 at 17:49







B Food

















asked Jan 1 at 17:40









B FoodB Food

386




386













  • The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

    – John Anderson
    Jan 1 at 18:32











  • wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

    – B Food
    Jan 1 at 19:18











  • In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

    – John Anderson
    Jan 1 at 22:11



















  • The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

    – John Anderson
    Jan 1 at 18:32











  • wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

    – B Food
    Jan 1 at 19:18











  • In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

    – John Anderson
    Jan 1 at 22:11

















The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

– John Anderson
Jan 1 at 18:32





The app.root is not the ScreenManager. You probably need something like app.root.ids.sm.current='a2', after adding sm as the id for the ScreenManager.

– John Anderson
Jan 1 at 18:32













wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

– B Food
Jan 1 at 19:18





wow.. it worked. thanks alot @JohnAnderson. So what is app.root.ids? what does each word represent?

– B Food
Jan 1 at 19:18













In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

– John Anderson
Jan 1 at 22:11





In the kv language you can refer to app, root, and self. The app refers to the running App. root refers to the root of the enclosing rule in the kv file. And self refers to the current widget. So, in my comment, you could actually leave out the app portion and just use root.ids.sm.current. See the docs. The ids is a dictionary that the kv language builds of the widgets.

– John Anderson
Jan 1 at 22:11












1 Answer
1






active

oldest

votes


















0














You have to analyze what app.root means and see if it is the ScreenManager.



app refers to the application that is the BoboApp instance, that is, main. root refers to the object that returns the build method of the application, that is, presentation. And presentation is the root object of the .kv, that is, the BoxLayout. With what we conclude that app.root is not the ScreenManager for which the error is valid.



Instead of using the root as a way to get to the ScreenManager it can be accessed through an id since the id is accessible within the whole tree.



On the other hand I have changed the names of the Screen to match the ones you want to set.



BoxLayout:
orientation: "horizontal"
BoxLayout:
ButtSection:
orientation: "vertical"
Button:
text: "Account One"
on_press: manager.current = "a1" # <---
Button:
text: "Account Two"
on_press: manager.current = "a2" # <---
Button:
text: "Account Three"
on_press: manager.current = "a3" # <---

ScreenManagement:
id: manager # <---
Welcome:
name: "a1" # <---
Label:
text: "Welcome To Bobot"
AccountOne:
name: "a2" # <---
Label:
text: "Page: Account One"
AccountTwo:
name: "a3" # <---
Label:
text: "Page: Account One"





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997568%2fhow-to-manage-screens-from-a-different-layout%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You have to analyze what app.root means and see if it is the ScreenManager.



    app refers to the application that is the BoboApp instance, that is, main. root refers to the object that returns the build method of the application, that is, presentation. And presentation is the root object of the .kv, that is, the BoxLayout. With what we conclude that app.root is not the ScreenManager for which the error is valid.



    Instead of using the root as a way to get to the ScreenManager it can be accessed through an id since the id is accessible within the whole tree.



    On the other hand I have changed the names of the Screen to match the ones you want to set.



    BoxLayout:
    orientation: "horizontal"
    BoxLayout:
    ButtSection:
    orientation: "vertical"
    Button:
    text: "Account One"
    on_press: manager.current = "a1" # <---
    Button:
    text: "Account Two"
    on_press: manager.current = "a2" # <---
    Button:
    text: "Account Three"
    on_press: manager.current = "a3" # <---

    ScreenManagement:
    id: manager # <---
    Welcome:
    name: "a1" # <---
    Label:
    text: "Welcome To Bobot"
    AccountOne:
    name: "a2" # <---
    Label:
    text: "Page: Account One"
    AccountTwo:
    name: "a3" # <---
    Label:
    text: "Page: Account One"





    share|improve this answer




























      0














      You have to analyze what app.root means and see if it is the ScreenManager.



      app refers to the application that is the BoboApp instance, that is, main. root refers to the object that returns the build method of the application, that is, presentation. And presentation is the root object of the .kv, that is, the BoxLayout. With what we conclude that app.root is not the ScreenManager for which the error is valid.



      Instead of using the root as a way to get to the ScreenManager it can be accessed through an id since the id is accessible within the whole tree.



      On the other hand I have changed the names of the Screen to match the ones you want to set.



      BoxLayout:
      orientation: "horizontal"
      BoxLayout:
      ButtSection:
      orientation: "vertical"
      Button:
      text: "Account One"
      on_press: manager.current = "a1" # <---
      Button:
      text: "Account Two"
      on_press: manager.current = "a2" # <---
      Button:
      text: "Account Three"
      on_press: manager.current = "a3" # <---

      ScreenManagement:
      id: manager # <---
      Welcome:
      name: "a1" # <---
      Label:
      text: "Welcome To Bobot"
      AccountOne:
      name: "a2" # <---
      Label:
      text: "Page: Account One"
      AccountTwo:
      name: "a3" # <---
      Label:
      text: "Page: Account One"





      share|improve this answer


























        0












        0








        0







        You have to analyze what app.root means and see if it is the ScreenManager.



        app refers to the application that is the BoboApp instance, that is, main. root refers to the object that returns the build method of the application, that is, presentation. And presentation is the root object of the .kv, that is, the BoxLayout. With what we conclude that app.root is not the ScreenManager for which the error is valid.



        Instead of using the root as a way to get to the ScreenManager it can be accessed through an id since the id is accessible within the whole tree.



        On the other hand I have changed the names of the Screen to match the ones you want to set.



        BoxLayout:
        orientation: "horizontal"
        BoxLayout:
        ButtSection:
        orientation: "vertical"
        Button:
        text: "Account One"
        on_press: manager.current = "a1" # <---
        Button:
        text: "Account Two"
        on_press: manager.current = "a2" # <---
        Button:
        text: "Account Three"
        on_press: manager.current = "a3" # <---

        ScreenManagement:
        id: manager # <---
        Welcome:
        name: "a1" # <---
        Label:
        text: "Welcome To Bobot"
        AccountOne:
        name: "a2" # <---
        Label:
        text: "Page: Account One"
        AccountTwo:
        name: "a3" # <---
        Label:
        text: "Page: Account One"





        share|improve this answer













        You have to analyze what app.root means and see if it is the ScreenManager.



        app refers to the application that is the BoboApp instance, that is, main. root refers to the object that returns the build method of the application, that is, presentation. And presentation is the root object of the .kv, that is, the BoxLayout. With what we conclude that app.root is not the ScreenManager for which the error is valid.



        Instead of using the root as a way to get to the ScreenManager it can be accessed through an id since the id is accessible within the whole tree.



        On the other hand I have changed the names of the Screen to match the ones you want to set.



        BoxLayout:
        orientation: "horizontal"
        BoxLayout:
        ButtSection:
        orientation: "vertical"
        Button:
        text: "Account One"
        on_press: manager.current = "a1" # <---
        Button:
        text: "Account Two"
        on_press: manager.current = "a2" # <---
        Button:
        text: "Account Three"
        on_press: manager.current = "a3" # <---

        ScreenManagement:
        id: manager # <---
        Welcome:
        name: "a1" # <---
        Label:
        text: "Welcome To Bobot"
        AccountOne:
        name: "a2" # <---
        Label:
        text: "Page: Account One"
        AccountTwo:
        name: "a3" # <---
        Label:
        text: "Page: Account One"






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 1 at 19:13









        eyllanesceyllanesc

        79.8k103258




        79.8k103258
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53997568%2fhow-to-manage-screens-from-a-different-layout%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Monofisismo

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas