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

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

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

      1. <small id='R7ojH'></small><noframes id='R7ojH'>

        <tfoot id='R7ojH'></tfoot>

        在 kivy lang 和 python 中訪問子小部件屬性的值

        Accessing value of child widget property in kivy lang and python(在 kivy lang 和 python 中訪問子小部件屬性的值)

                <tbody id='Ybipu'></tbody>
                • <bdo id='Ybipu'></bdo><ul id='Ybipu'></ul>

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

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

                • <i id='Ybipu'><tr id='Ybipu'><dt id='Ybipu'><q id='Ybipu'><span id='Ybipu'><b id='Ybipu'><form id='Ybipu'><ins id='Ybipu'></ins><ul id='Ybipu'></ul><sub id='Ybipu'></sub></form><legend id='Ybipu'></legend><bdo id='Ybipu'><pre id='Ybipu'><center id='Ybipu'></center></pre></bdo></b><th id='Ybipu'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ybipu'><tfoot id='Ybipu'></tfoot><dl id='Ybipu'><fieldset id='Ybipu'></fieldset></dl></div>
                  <tfoot id='Ybipu'></tfoot>
                  本文介紹了在 kivy lang 和 python 中訪問子小部件屬性的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  1. 如何覆蓋 Kivy 小部件子部件的默認值?即 MyWidget.label 是默認",但我想將其更改為例如當 MyRootWidget 的孩子時出現紫龜"?

                  1. How can I overwrite the default value of a Kivy widget's child? i.e. MyWidget.label is 'default' but I want to change it to e.g. 'purple turtle' when a child of MyRootWidget?

                  我可以像在MyRootWidget.__init__()中那樣訪問children的children,但是看起來很麻煩,尤其是對于一棵很深的樹...有沒有更優雅的怎么辦?

                  I can access the children of children as I've done in MyRootWidget.__init__(), but it seems cumbersome, especially for a deep tree ... is there a more elegant way of doing it?

                  我一直在查看 Kivy lang 和 Widget 頁面,但無法理解是否存在解決方案.我在 SO 頁面中還沒有看到這個問題(盡管在我搜索時確實回答了一個不同的問題).

                  I've been looking over the Kivy lang and Widget pages, but haven't been able to understand a solution if it's there. I haven't seen quite this issue in SO pages (though the did answer a different question while I was searching).

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import ObjectProperty, StringProperty
                  
                  
                  root = Builder.load_string('''
                  <MyWidget@BoxLayout>:
                      orientation: 'vertical'
                      Label:
                          id: label
                          text: 'DEFAULT'
                  
                  <MyRootWidget@BoxLayout>:
                      id: root_widget
                      MyWidget:
                          id: w1
                          # (---1---) 
                  ''')
                  
                  
                  class MyRootWidget(BoxLayout):
                      w1 = ObjectProperty()
                  
                      def __init__(self, **kwargs):
                          super().__init__(**kwargs)
                          print(self.ids.w1.ids.label.text)  # (---2---)
                  
                  
                  class MainApp(App):
                      def build(self):
                          return MyRootWidget()
                  
                  
                  if __name__ == '__main__':
                      MainApp().run()
                  

                  推薦答案

                  首先,在實現任何代碼之前,你必須設計你的類.

                  First of all, before implementing any code, you must design your classes.

                  首先我們將使用 MyWidget,在您的要求中表明您希望文本是可修改的,因此它必須是根屬性.

                  First we will do it with MyWidget, in your requirements you indicate that you want the text to be modifiable so it must be a root property.

                  MyWidget
                  ┌--------------------------┐
                  |                          |
                  | ┌-------------┐   text---┼--->
                  | | Label       |     |    |
                  | |    *text ---┼-----┘    |
                  | └-------------┘          |
                  └--------------------------┘
                  

                  MyRootWidget 也可以這樣做:

                  The same could be done with MyRootWidget:

                  MyRootWidget
                  ┌-----------------------------┐
                  |                             |
                  | ┌-------------┐ obj_widget--┼--->
                  | | MyWidget  --┼-----┘       |
                  | |             |             |
                  | └-------------┘             |
                  └-----------------------------┘
                  

                  屬性的深度取決于您的要求,但如果我們觀察到公開屬性,則意味著在根中創建屬性并進行綁定,以便在修改根屬性時也會修改內部屬性.

                  The depth of the property depends on your requirements, but if we observe exposing a property it implies creating a property in the root and making a binding so that when the root property is modified the internal property is modified as well.

                  實現上述你會得到以下結果:

                  Implementing the above you get the following:

                  from kivy.app import App
                  from kivy.lang import Builder
                  from kivy.uix.boxlayout import BoxLayout
                  from kivy.properties import ObjectProperty, StringProperty
                  
                  root = Builder.load_string('''
                  <MyWidget@BoxLayout>:
                      text: "DEFAULT"
                      obj_label: label
                      orientation: 'vertical'
                      Label:
                          id: label
                          text: root.text
                  
                  <MyRootWidget@BoxLayout>:
                      obj_widget: w1
                      MyWidget:
                          id: w1
                          text: "purple turtle"
                  ''')
                  
                  class MyRootWidget(BoxLayout):
                      def __init__(self, **kwargs):
                          super().__init__(**kwargs)
                          print(self.obj_widget.text) 
                  
                  class MainApp(App):
                      def build(self):
                          return MyRootWidget()
                  
                  if __name__ == '__main__':
                      MainApp().run()
                  

                  因此,為了避免 id,您可以為子小部件創建一個別名,就像我對 obj_widget 所做的那樣,它是 w1 的別名.

                  So to avoid the ids you can create an alias to the children widget like I did with obj_widget which is an alias of w1.

                  按照設計,您不應該直接訪問完整的樹,但您必須修改層的屬性,如果修改了該層,則必須更新其內部的必要數據,以避免類之間的耦合.

                  By design you should not access the complete tree directly but you must modify the property of a layer and this layer if it is modified then you must update the necessary data in its internal part so we avoid the coupling between classes.

                  這篇關于在 kivy lang 和 python 中訪問子小部件屬性的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)

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

                            主站蜘蛛池模板: 中文字幕一级毛片视频 | 波多野结衣精品在线 | 日韩精品一区二区三区视频播放 | 国产精品久久久久久一区二区三区 | 亚洲高清视频在线观看 | 亚洲一区二区视频 | 亚洲精品久久久一区二区三区 | 国产日韩精品一区二区三区 | 四虎成人在线播放 | 亚洲一区 中文字幕 | 国产精品久久免费观看 | 国产精品久久777777 | 国产综合久久久久久鬼色 | 亚洲品质自拍视频网站 | 国产午夜一级 | 中国美女av | 欧美成人a | 国产一区视频在线 | 7777精品伊人久久精品影视 | 久久久999国产精品 中文字幕在线精品 | 久久久久久成人 | 亚洲精品专区 | 欧美视频网| 欧美精品成人 | 精品国产成人 | 午夜小电影| 日本不卡一二三 | 人操人人| 91网在线观看 | 天天操天天射天天 | 欧美综合一区二区 | 日韩免费视频 | 成人网视频 | 欧美在线观看一区二区 | 欧美日韩在线免费 | 一区二区三区视频在线 | 日韩电影中文字幕 | 久久久久久高潮国产精品视 | 久久精品国产99国产精品 | 国产午夜精品一区二区三区嫩草 | 看黄在线 |