<tfoot id='KRITy'></tfoot>

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

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

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

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

      1. StringProperty 的 TextInput 的 kivy 参考文本

        时间:2023-10-09

        1. <small id='40rR9'></small><noframes id='40rR9'>

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

              <tbody id='40rR9'></tbody>

            • <bdo id='40rR9'></bdo><ul id='40rR9'></ul>

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

                  问题描述

                  我想通过 StringProperty 获取 TextInput 的文本,但它不起作用.我得到一个空字符串.在第二个示例中,我将整个 TextInput 声明为 ObjectProperty,然后它就可以工作了.我的第一个例子有什么问题?

                  I would like to get the text of my TextInput via a StringProperty, but it does not work. I get an empty string. In the second example, I am declaring the whole TextInput as an ObjectProperty and then it does work. What is wrong with my first example?

                  第一个示例不打印 TextInput 的文本例子1.py

                  from kivy.app import App
                  from kivy.base import Builder
                  from kivy.properties import StringProperty
                  from kivy.uix.boxlayout import BoxLayout
                  
                  Builder.load_string("""
                  <rootwi>:
                      orientation: 'vertical'
                      Button:
                          on_press: root.print_txt()
                      TextInput:
                          text: root.textinputtext
                  """)
                  class rootwi(BoxLayout):
                      textinputtext = StringProperty()
                  
                      def print_txt(self):
                          print(self.textinputtext)
                  
                  
                  class MyApp(App):
                      def build(self):
                          return rootwi()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  第二个示例打印 TextInput 的文本,但使用 ObjectProperty 而不是 StringProperty example2.py

                  Second example does print text of TextInput, but uses a ObjectProperty not StringProperty example2.py

                  from kivy.app import App
                  from kivy.base import Builder
                  from kivy.properties import ObjectProperty
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.clock import Clock
                  
                  
                  Builder.load_string("""
                  <rootwi>:
                      txt: txt
                      orientation: 'vertical'
                      Button:
                          on_press: root.print_txt()
                      TextInput:
                          id: txt
                  """)
                  class rootwi(BoxLayout):
                      txt = ObjectProperty()
                  
                      def print_txt(self):
                          print(self.txt.text)
                  
                  
                  class MyApp(App):
                      def build(self):
                          return rootwi()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  如果我将文本设置为特定的,它会显示在 TextInput 中.(但仍然无法打印)

                  from kivy.app import App
                  from kivy.base import Builder
                  from kivy.properties import StringProperty
                  from kivy.uix.boxlayout import BoxLayout
                  
                  Builder.load_string("""
                  <rootwi>:
                      orientation: 'vertical'
                      Button:
                          on_press: root.print_txt()
                      TextInput:
                          text: root.textinputtext
                  """)
                  class rootwi(BoxLayout):
                      textinputtext = StringProperty()
                  
                      def __init__(self, **kwargs):
                          self.textinputtext = 'palim'
                          super(rootwi, self).__init__(**kwargs)
                  
                      def print_txt(self):
                          print(self.textinputtext)
                  
                  
                  class MyApp(App):
                      def build(self):
                          return rootwi()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  推荐答案

                  如果你想使用 StringProperty 设置和获取文本,那么你应该创建一个双向绑定:

                  If you want set and get the text using the StringProperty then you should create a bidirectional bind:

                  from kivy.app import App
                  from kivy.base import Builder
                  from kivy.properties import StringProperty, ObjectProperty
                  from kivy.uix.boxlayout import BoxLayout
                  
                  
                  Builder.load_string("""
                  <rootwi>:
                      orientation: 'vertical'
                      textinputtext: txt.text
                      Button:
                          on_press: root.print_txt()
                      TextInput:
                          id: txt
                          text: root.textinputtext
                  """)
                  
                  class rootwi(BoxLayout):
                      textinputtext = StringProperty()
                  
                      def __init__(self, **kwargs):
                          super(rootwi, self).__init__(**kwargs)
                          self.textinputtext = 'palim'
                  
                      def print_txt(self):
                          print(self.textinputtext)
                  
                  
                  
                  class MyApp(App):
                      def build(self):
                          return rootwi()
                  
                  if __name__ == '__main__':
                      MyApp().run()
                  

                  输出:

                  这篇关于StringProperty 的 TextInput 的 kivy 参考文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:带有复选框的 Kivy 多项选择 下一篇:如何修复“没有名为 'kivy._clock' 的模块&q

                  相关文章

                  最新文章

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

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

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