• <small id='Wc7zv'></small><noframes id='Wc7zv'>

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

        • <bdo id='Wc7zv'></bdo><ul id='Wc7zv'></ul>

        kv 语言中的 Kivy 屏幕管理器参考

        Kivy Screen manager reference in kv language(kv 语言中的 Kivy 屏幕管理器参考)
          <tbody id='2AW21'></tbody>
          <bdo id='2AW21'></bdo><ul id='2AW21'></ul>

            <small id='2AW21'></small><noframes id='2AW21'>

              <legend id='2AW21'><style id='2AW21'><dir id='2AW21'><q id='2AW21'></q></dir></style></legend>
              • <i id='2AW21'><tr id='2AW21'><dt id='2AW21'><q id='2AW21'><span id='2AW21'><b id='2AW21'><form id='2AW21'><ins id='2AW21'></ins><ul id='2AW21'></ul><sub id='2AW21'></sub></form><legend id='2AW21'></legend><bdo id='2AW21'><pre id='2AW21'><center id='2AW21'></center></pre></bdo></b><th id='2AW21'></th></span></q></dt></tr></i><div id='2AW21'><tfoot id='2AW21'></tfoot><dl id='2AW21'><fieldset id='2AW21'></fieldset></dl></div>
                  <tfoot id='2AW21'></tfoot>
                  本文介绍了kv 语言中的 Kivy 屏幕管理器参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试制作一个主菜单,让我在单击按钮时切换屏幕,但我不知道如何从按钮中引用管理器.

                  I'm trying to make a main menu that lets me switch Screens when I click a button, but I can't figure out how to reference the manager from the button.

                  我有一个主菜单页面的设置(在 kv 文件中):

                  I have a setup for a main menu page (in kv file):

                  <MainMenu>:  #AnchorLayout
                       BoxLayout:
                           Button:
                               text: "button 1"
                           Button:
                               text: "change screen"
                               on_release: root.manager.current = "OtherPage"
                  
                  <MainWidget>:
                      screen_manger: screen_manager
                      ScreenManger:
                          id: screen_manger
                          Screen:
                              name: "MainMenu"
                              MainMenu
                          Screen:
                              name: "OtherPage"
                              OtherPage    #this is defined in the kv file, just lazy to type it.
                  

                  当我点击按钮 Change Screen 时,我得到:

                  When I click on the Button Change Screen, i get:

                  AttributeError: 'MainMenu' object has no attribute 'manager'
                  

                  老实说,这并不让我感到惊讶.我想我可以通过在 python 代码中编写所有布局并在 BoxLayoutMainMenu 小部件中添加对屏幕管理器的引用来解决这个问题,但我不知道如何在 kv 文件中执行此操作.

                  which, in all honesty doesn't supprise me. I figure I can work around this by writing all the layout in python code and adding a reference to the screen manager in the BoxLayout or MainMenu widgets, but I have no idea how to do this in the kv file.

                  推荐答案

                  更好理解问题后重新做答案:

                  Re-doing the answer after understanding the issue better:

                  您的 MainWidget 实例不知道 screen_manager 引用,它没有传递给它(并且在其规则中 root 引用 MainWidget 实例,而不是 ScreenManager 一个.

                  Your MainWidget instance doesn't know about the screen_manager reference, it's not passed to it (and in its rule root refer to the MainWidget instance, not the ScreenManager one.

                  如果您将 manager: screen_manager 放在 MainWidget 实例的声明下(第 15 行),然后将 manager ObjectProperty 添加到 pythonMainWidget 的声明,那么您的绑定将起作用.

                  If you put manager: screen_manager under the declaration of MainWidget instance (line 15), and you add a manager ObjectProperty to the python declaration of MainWidget, then your binding will work.

                  蟒蛇:

                  class MainWidget(Widget):
                      manager = ObjectProperty(None)
                  

                  kv:

                  <MainWidget>:
                      screen_manger: screen_manager
                      ScreenManger:
                          id: screen_manger
                          Screen:
                              name: "MainMenu"
                              MainMenu:
                                  manager: screen_manager
                          Screen:
                              name: "OtherPage"
                  

                  那么它应该可以按您的意愿工作.

                  then it should work as you want it.

                  另外,qua-non 的这个 wiki 条目可能会有所帮助 https://github.com/kivy/kivy/wiki/Linking-ScreenManager-to-a-different-Widget

                  edit: also, this wiki entry by qua-non could be helpful https://github.com/kivy/kivy/wiki/Linking-ScreenManager-to-a-different-Widget

                  这篇关于kv 语言中的 Kivy 屏幕管理器参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Kivy 1.9.0 Windows package KeyError: #39;rthooks#39;(Kivy 1.9.0 Windows 包 KeyError: rthooks)
                  Python Kivy: how to call a function on button click?(Python Kivy:如何在按钮单击时调用函数?)
                  How to disable a widget in Kivy?(如何禁用 Kivy 中的小部件?)
                  Centering an object in Kivy(在 Kivy 中将对象居中)
                  How to downgrade to Python 3.4 from 3.5(如何从 Python 3.5 降级到 Python 3.4)
                  Change button or label text color in kivy(在kivy中更改按钮或标签文本颜色)

                    <tfoot id='JHAcx'></tfoot>

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

                            <legend id='JHAcx'><style id='JHAcx'><dir id='JHAcx'><q id='JHAcx'></q></dir></style></legend>

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