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

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

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

      <legend id='QUyqb'><style id='QUyqb'><dir id='QUyqb'><q id='QUyqb'></q></dir></style></legend>
      1. <tfoot id='QUyqb'></tfoot>

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

        时间:2023-10-09

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

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

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

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

                • <tfoot id='p6DVB'></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:

                  ma​​in.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 - 屏幕管理器 - 访问其他类中的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:基维.文本提供程序错误 下一篇:我如何使用 Kivy (Python) 相机

                  相关文章

                  最新文章

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

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