<legend id='0J1Mw'><style id='0J1Mw'><dir id='0J1Mw'><q id='0J1Mw'></q></dir></style></legend>

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

        <bdo id='0J1Mw'></bdo><ul id='0J1Mw'></ul>
      1. <small id='0J1Mw'></small><noframes id='0J1Mw'>

        Kivy - 屏幕管理器 - 访问其他类中的属性

        Kivy - Screen Manager - Accessing attribute in other class(Kivy - 屏幕管理器 - 访问其他类中的属性)
        <legend id='CKD0g'><style id='CKD0g'><dir id='CKD0g'><q id='CKD0g'></q></dir></style></legend>
              <bdo id='CKD0g'></bdo><ul id='CKD0g'></ul>

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

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

                  本文介绍了Kivy - 屏幕管理器 - 访问其他类中的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  使用 Kivy 屏幕管理器,我创建了两个屏幕.在屏幕 1 中,我想更改屏幕 2 中的标签.我在我的代码中突出显示有问题的区域:

                  Using the Kivy Screen Manager, I create two Screens. Whilst being in screen 1, i want to change a label in screen two. I highlight the problematic area in my code:

                  我的test.ky:

                  #: import ScreenManager kivy.uix.screenmanager.ScreenManager
                  #: import Screen kivy.uix.screenmanager.ScreenManager
                  #: import SettingsScreen screen
                  
                  
                  ScreenManager:
                      MenuScreen:
                      SettingsScreen:
                  
                  
                  <MenuScreen>:
                      name: 'MenuScreen'
                      BoxLayout:
                          Button:
                              text: 'Goto nn'
                              on_press: 
                                  root.manager.current = 'SettingsScreen'
                                  root.change_text()
                  
                  
                  <SettingsScreen>:
                      name: 'SettingsScreen'
                      label_id: label_field
                      BoxLayout:
                          Label:
                              id: label_field
                              text: "to_be_changed"
                  

                  还有我的 screen.py

                  from kivy.app import App
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.uix.screenmanager import ScreenManager, Screen
                  
                  
                  class MenuScreen(Screen):
                      def change_text(self):
                          pass
                          # HERE: something like
                          # root.SettingsScreen.label_field.text = 'new text'
                  
                  
                  class SettingsScreen(Screen):
                      pass
                  
                  
                  class TestApp(App):
                      pass
                  
                  TestApp().run()
                  

                  非常感谢任何帮助!谢谢,尼科

                  Any help is greatly appreciated! Thanks, Nico

                  推荐答案

                  这个怎么样:

                  当您按下 MenuScreen 上的按钮时,它会在自身上设置一个属性,其中包含您要放在 SettingsScreen 标签中的文本.然后在kv文件中给MenuScreen分配一个id值,用来引用这个属性.示例:

                  When you press the button on MenuScreen, it sets an attribute on itself containing the text you want to put in the SettingsScreen Label. Then the MenuScreen is assigned an id value in the kv file, which is used to reference this attribute. Example:

                  main.py

                  class MenuScreen(Screen):
                      text = StringProperty('')
                      def change_text(self):
                          self.text = "The text you want to set"
                          self.manager.current = "SettingsScreen"
                  
                  class SettingsScreen(Screen):
                      label_text = StringProperty('')
                  

                  kv 文件

                  ScreenManager:
                      id: screen_manager
                      MenuScreen:
                          id: menu_screen
                          name: 'MenuScreen'
                          manager: screen_manager
                      SettingsScreen:
                          name: 'SettingsScreen'
                          manager: screen_manager
                          label_text: menu_screen.text
                  
                  <MenuScreen>:
                      BoxLayout:
                          Button:
                              text: 'Goto nn'
                              on_press:
                                  root.change_text()
                  
                  <SettingsScreen>:
                      BoxLayout:
                          Label:
                              text: root.label_text
                  

                  如您所见,我在 kv 文件中的 ScreenManager 下设置了屏幕的名称和 id,因为这是我通常会做的事情.

                  As you can see, I set the names and id of the screens under ScreenManager itself in the kv file, as this is what I would usually do to make this work.

                  这篇关于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中更改按钮或标签文本颜色)
                    <tbody id='mobHZ'></tbody>

                      <bdo id='mobHZ'></bdo><ul id='mobHZ'></ul>

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

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

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