<bdo id='V9vNW'></bdo><ul id='V9vNW'></ul>
  • <i id='V9vNW'><tr id='V9vNW'><dt id='V9vNW'><q id='V9vNW'><span id='V9vNW'><b id='V9vNW'><form id='V9vNW'><ins id='V9vNW'></ins><ul id='V9vNW'></ul><sub id='V9vNW'></sub></form><legend id='V9vNW'></legend><bdo id='V9vNW'><pre id='V9vNW'><center id='V9vNW'></center></pre></bdo></b><th id='V9vNW'></th></span></q></dt></tr></i><div id='V9vNW'><tfoot id='V9vNW'></tfoot><dl id='V9vNW'><fieldset id='V9vNW'></fieldset></dl></div>

    <small id='V9vNW'></small><noframes id='V9vNW'>

      1. <legend id='V9vNW'><style id='V9vNW'><dir id='V9vNW'><q id='V9vNW'></q></dir></style></legend><tfoot id='V9vNW'></tfoot>
      2. 嵌套在 BoxLayout 内的 ScreenManager 不可见

        时间:2023-10-09
            <tfoot id='30QgU'></tfoot>

              <tbody id='30QgU'></tbody>
                <bdo id='30QgU'></bdo><ul id='30QgU'></ul>

                <legend id='30QgU'><style id='30QgU'><dir id='30QgU'><q id='30QgU'></q></dir></style></legend>
              • <small id='30QgU'></small><noframes id='30QgU'>

                • <i id='30QgU'><tr id='30QgU'><dt id='30QgU'><q id='30QgU'><span id='30QgU'><b id='30QgU'><form id='30QgU'><ins id='30QgU'></ins><ul id='30QgU'></ul><sub id='30QgU'></sub></form><legend id='30QgU'></legend><bdo id='30QgU'><pre id='30QgU'><center id='30QgU'></center></pre></bdo></b><th id='30QgU'></th></span></q></dt></tr></i><div id='30QgU'><tfoot id='30QgU'></tfoot><dl id='30QgU'><fieldset id='30QgU'></fieldset></dl></div>
                  本文介绍了嵌套在 BoxLayout 内的 ScreenManager 不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在试验 Kivy,并试图在 BoxLayout 中嵌套一个 ScreenManager 实例.我遇到的问题是,当 ScreenManager 是 BoxLayout 的子小部件时,ScreenManager 及其屏幕不显示.

                  I am experimenting with Kivy and am trying to nest a ScreenManager instance inside of a BoxLayout. The problem I am having is that the ScreenManager and its Screen do not show when the ScreenManager is a child widget of the BoxLayout.

                  此代码显示黑屏.

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.label import Label
                  from kivy.uix.screenmanager import Screen, ScreenManager
                  
                  
                  class MenuScreen(Screen):
                  
                      def __init__(self, **kwargs):
                          super(Screen, self).__init__(**kwargs)
                          self.add_widget(Label(text="Some text."))
                  
                  screen_manager = ScreenManager()
                  screen_manager.add_widget(MenuScreen(name="menu"))
                  
                  
                  class Container(BoxLayout):
                  
                      def __init__(self, **kwargs):
                          super(BoxLayout, self).__init__(**kwargs)
                          self.add_widget(screen_manager)
                  
                  
                  class NestedScreenManagerApp(App):
                  
                      def build(self):
                          """
                          :return: a BoxLayout with the screen manager nested inside it
                          """
                          return Container()
                  
                  
                  if __name__ == "__main__":
                      NestedScreenManagerApp().run()
                  

                  另一方面,这段代码(它直接将 ScreenManager 作为根小部件返回)确实有效,并且 MenuScreen 及其标签是可见的.将 ScreenManager 作为根小部件返回正是 官方屏幕管理器示例应用程序 会.

                  On the other hand, this code (which returns the ScreenManager directly as the root widget) does work and the MenuScreen and its Label are visible. Returning the ScreenManager as the root widget is exactly what the official screen manager example app does.

                  from kivy.app import App
                  from kivy.uix.label import Label
                  from kivy.uix.screenmanager import Screen, ScreenManager
                  
                  
                  class MenuScreen(Screen):
                  
                      def __init__(self, **kwargs):
                          super(Screen, self).__init__(**kwargs)
                          self.add_widget(Label(text="Some text."))
                  
                  screen_manager = ScreenManager()
                  screen_manager.add_widget(MenuScreen(name="menu"))
                  
                  
                  class RootScreenManagerApp(App):
                  
                      def build(self):
                          """
                          :return: the screen manager directly
                          """
                          return screen_manager
                  
                  
                  if __name__ == "__main__":
                      RootScreenManagerApp().run()
                  

                  当 ScreenManager 及其 Screen 是我的 Container(BoxLayout) 的子小部件时,如何让其可见?我想我错过了一些非常简单的东西.

                  How can I get the ScreenManager and its Screen to be visible when it is child widget of my Container(BoxLayout)? I think I am missing something really simple.

                  我在 Python 2.7.9 上使用 Kivy 1.8.0,在 Debian Jessie 上运行.

                  I am using Kivy 1.8.0 on Python 2.7.9, running on Debian Jessie.

                  推荐答案

                  我找到了解决方案;问题是我在 Container.__init__ 方法中调用了 super(BoxLayout, self) 而不是 super(Container, self) .一旦我改变了这个,ScreenManager 和它的屏幕就可以在 Container 中看到了.

                  I found the solution; the problem was I was calling super(BoxLayout, self) instead of super(Container, self) in my Container.__init__ method. Once I changed this, the ScreenManager and its screen became visible from within the Container.

                  这篇关于嵌套在 BoxLayout 内的 ScreenManager 不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我如何在我的 kivy 程序中使用 json api 下一篇:如何在类方法初始化之前加载 Kivy ID(Python with K

                  相关文章

                  最新文章

                  <i id='lSezH'><tr id='lSezH'><dt id='lSezH'><q id='lSezH'><span id='lSezH'><b id='lSezH'><form id='lSezH'><ins id='lSezH'></ins><ul id='lSezH'></ul><sub id='lSezH'></sub></form><legend id='lSezH'></legend><bdo id='lSezH'><pre id='lSezH'><center id='lSezH'></center></pre></bdo></b><th id='lSezH'></th></span></q></dt></tr></i><div id='lSezH'><tfoot id='lSezH'></tfoot><dl id='lSezH'><fieldset id='lSezH'></fieldset></dl></div>

                    1. <small id='lSezH'></small><noframes id='lSezH'>

                        <bdo id='lSezH'></bdo><ul id='lSezH'></ul>
                      <legend id='lSezH'><style id='lSezH'><dir id='lSezH'><q id='lSezH'></q></dir></style></legend>
                    2. <tfoot id='lSezH'></tfoot>