久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <tfoot id='kj57C'></tfoot>

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

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

      Kivy ObjectProperty 更新標簽文本

      Kivy ObjectProperty to update label text(Kivy ObjectProperty 更新標簽文本)
      <legend id='UKqoM'><style id='UKqoM'><dir id='UKqoM'><q id='UKqoM'></q></dir></style></legend>

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

          <tbody id='UKqoM'></tbody>

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

              • <bdo id='UKqoM'></bdo><ul id='UKqoM'></ul>
              • 本文介紹了Kivy ObjectProperty 更新標簽文本的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我正在創建一個 kivy 用戶界面來顯示由我作為標準 python 對象編寫的數據模型生成的值.本質上,我希望用戶能夠按下一個按鈕,這將改變底層數據模型,并且這種改變的結果將自動更新和顯示.據我了解,這可以使用 kivy 屬性(在本例中為 ObjectProperty)來實現.

                I am working on creating a kivy user interface to display the values generated by a data model I've written as a standard python object. In essence, I would like the user to be able to press a button, which would change the underlying data model and the results of this change would be automatically updated and displayed. It is my understanding that this can be implemented using kivy properties (in this case, ObjectProperty).

                下面是一些示例代碼:

                import kivy
                kivy.require('1.7.0')
                
                from kivy.app import App
                from kivy.uix.gridlayout import GridLayout
                from kivy.properties import ObjectProperty
                from kivy.lang import Builder
                
                Builder.load_string("""
                <RootWidget>:
                    cols: 2
                    Label:
                        text: "Attribute a:"
                    Label:
                        text: root.data_model.a
                    Label:
                        text: "Attribute b:"
                    Label:
                        text: root.data_model.b
                    Label:
                        text: "Attribute c:"
                    Label:
                        text: root.data_model.c
                    Button:
                        text: "Make data_model.a longer"
                        on_press: root.button_press()
                    Button:
                        text: "Make data_model.b shorter"
                        on_press: root.button_press2()
                """)
                
                
                class DataModel(object):
                    def __init__(self):
                        self.a = 'This is a'
                        self.b ='This is b'
                
                    @property
                    def c(self):
                        return self.a + ' and ' + self.b
                
                class RootWidget(GridLayout):
                    data_model = ObjectProperty(DataModel())
                
                    def button_press(self, *args):
                        self.data_model.a = 'This is a and it is really long now'
                        print self.data_model.c
                
                    def button_press2(self, *args):
                        self.data_model.b = 'B'
                        print self.data_model.c
                
                class TestApp(App):
                    def build(self):
                        return RootWidget()
                
                app = TestApp()
                app.run()
                

                所需的結果是當用戶按下任一按鈕時,標簽會自動更新以顯示新屬性.從打印語句可以看出,data_model 正在正確更新.但是,沒有一個標簽正在更新.有人可以澄清如何做到這一點嗎?

                The desired result is for when user presses either button, the labels would automatically update to show the new properties. As can be seen by the print statements, the data_model is getting updated correctly. However, none of the labels are updating. Can someone clarify how to do this?

                推薦答案

                但是,所有標簽都沒有更新.有人可以澄清如何做到這一點嗎?

                However, none of the labels are updating. Can someone clarify how to do this?

                你引用的屬性需要是Kivy屬性,但是你引用的abc都是python屬性所以Kivy無法綁定到他們的更改.

                The attributes you reference need to be Kivy properties, but the a, b and c you reference are all just python attributes so Kivy has no way to bind to their changes.

                要使用屬性,您需要您的對象從 EventDispatcher 繼承(Kivy 小部件會自動執行此操作,這就是它們的屬性起作用的原因).

                To work with properties you need your object to inherit from EventDispatcher (Kivy widgets do this automatically, which is why their properties work).

                from kivy.event import EventDispatcher
                
                class DataModel(EventDispatcher):
                    a = StringProperty('')
                    b = StringProperty('')
                    c = StringProperty('')
                
                    def __init__(self, *args, **kwargs):
                        super(DataModel, self).__init__(*args, **kwargs)
                        self.a = 'This is a'
                        self.b ='This is b'
                        self.bind(a=self.set_c)
                        self.bind(b=self.set_c)
                
                    def set_c(self, instance, value):
                        self.c = self.a + ' and ' + self.b        
                

                請注意,這不是獲得你想要的 c 行為的唯一方法(甚至不一定是最好的方法).您可以使用 kv 語言創建綁定(我通常會這樣做),或者您可以查看 Kivy 的 AliasProperty 以獲得更類似于您的原始定義的內容.

                Note that this is not the only way (or even necessarily the best way) to get the behaviour you wanted for c. You could create the binding in kv language (I'd usually do it that way) or you can look at Kivy's AliasProperty for something more like your original definition.

                當然你也可以在聲明屬性時設置 a 和 b 的值.

                Of course you could also set the values of a and b when the properties are declared.

                這篇關于Kivy ObjectProperty 更新標簽文本的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <tbody id='apgWA'></tbody>

                  <i id='apgWA'><tr id='apgWA'><dt id='apgWA'><q id='apgWA'><span id='apgWA'><b id='apgWA'><form id='apgWA'><ins id='apgWA'></ins><ul id='apgWA'></ul><sub id='apgWA'></sub></form><legend id='apgWA'></legend><bdo id='apgWA'><pre id='apgWA'><center id='apgWA'></center></pre></bdo></b><th id='apgWA'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='apgWA'><tfoot id='apgWA'></tfoot><dl id='apgWA'><fieldset id='apgWA'></fieldset></dl></div>
                1. <small id='apgWA'></small><noframes id='apgWA'>

                  <tfoot id='apgWA'></tfoot>
                    • <bdo id='apgWA'></bdo><ul id='apgWA'></ul>
                      <legend id='apgWA'><style id='apgWA'><dir id='apgWA'><q id='apgWA'></q></dir></style></legend>

                        • 主站蜘蛛池模板: 日韩中文一区 | 97操操| 91精品久久久久久久久中文字幕 | 黄色免费观看网站 | www.国产一区 | 亚洲综合区 | 在线观看成人小视频 | 国产成人99久久亚洲综合精品 | 久久精品中文 | 精品久久久久久久 | 99综合 | 中文字幕亚洲无线 | 国产乡下妇女做爰 | 91精品国产91久久久久青草 | 一级欧美黄色片 | 免费日韩av | 综合色播 | 日本一区二区三区免费观看 | 午夜在线电影网 | 亚洲欧美日韩网站 | 久久精品国产久精国产 | 国产99久久精品一区二区300 | 亚洲一区中文 | 99精品久久| 成在线人视频免费视频 | 日韩毛片中文字幕 | 国产精品久久久久一区二区三区 | 男女下面一进一出网站 | 免费在线观看黄网站 | 欧美黑人一级爽快片淫片高清 | 精品国产一区二区三区久久狼黑人 | 精品久久久久国产 | 毛片久久久 | h视频在线看 | 国产在线永久免费 | 国产成人精品久久二区二区 | 日韩免费高清视频 | 久久久久国产精品www | 久久久久亚洲精品 | a级片在线观看 | 99久久久99久久国产片鸭王 |