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

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

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

      Kivy 外部規則繼承 2

      Kivy outside rule inherence 2(Kivy 外部規則繼承 2)

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

    1. <legend id='MRohu'><style id='MRohu'><dir id='MRohu'><q id='MRohu'></q></dir></style></legend>
          <bdo id='MRohu'></bdo><ul id='MRohu'></ul>

              • <tfoot id='MRohu'></tfoot>
                  <tbody id='MRohu'></tbody>

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

                本文介紹了Kivy 外部規則繼承 2的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                作為后續問題:

                • Kivy 外部規則繼承
                • 使用 add_widget() 繼承 Kivy 規則李>

                main.py

                import os
                from kivy.app import App
                from kivy.uix.button import Button
                from kivy.uix.stacklayout import StackLayout
                from kivy.properties import ObjectProperty
                
                
                class FancyButton(Button):
                    imp = ObjectProperty(None)
                
                
                class Important(StackLayout):
                
                    font_kanji = os.path.join('fonts', 'TakaoPMincho.ttf')
                
                    def NoInspiration(self, smile):
                        print("Received: {}".format(smile))
                
                    def AddFancy(self):
                        print(self.ids)
                        temp = FancyButton(text='f', imp = self)
                        self.ids.boxy.add_widget(temp)
                
                
                class TestApp(App):
                    def build(self):
                        pass
                
                if __name__ == '__main__':
                    TestApp().run()
                

                test.kv

                #:kivy 1.9.0
                
                <FancyButton>:
                    font_name: self.imp.font_kanji  # ERROR
                    on_release: self.imp.NoInspiration(':)')  # WORKS
                
                
                <Important>:
                    id: imp
                
                    BoxLayout:
                        id: boxy
                        orientation: 'vertical'
                
                        FancyButton:
                            text: "smiley"
                            imp: root
                
                        Button:
                            text: "add fancy"
                            on_release: imp.AddFancy()
                
                
                BoxLayout:
                    Important
                

                在上面的示例中,'on_release: self.imp.NoInspiration(':)')' 有效,因為 FancyButton 具有 'imp: root'.

                In the above example 'on_release: self.imp.NoInspiration(':)')' works because FancyButton has 'imp: root'.

                但是 'font_name: self.imp.font_kanji' 不起作用并給出錯誤:

                However 'font_name: self.imp.font_kanji' doesn't work and gives the error:

                AttributeError: 'NoneType' 對象沒有屬性 'font_kanji'

                AttributeError: 'NoneType' object has no attribute 'font_kanji'

                我的猜測是這樣做的原因是 on_release 發生在所有小部件都直接加載和 font_name 之后,所以沒有'imp:root'.

                My guess is the reason for this is that on_release takes place after all widgets are loaded and font_name directly, so without having 'imp: root'.

                我也試過了:

                font_kanji = StringProperty(os.path.join('fonts', 'TakaoPMincho.ttf'))
                

                ,但無濟于事.

                如何讓 font_name 引用 font_kanji?我應該使用全局嗎?如果是,您將如何在 Python 中設置可以在 .kv 中訪問的全局?

                How do I get font_name refer to font_kanji? Should I use global? If yes, how would you set a global in Python which can be accessed in the .kv?

                (如果我將 global 放在 font_Kanji 前面并刪除 .kv 文件中的 'self.imp' 我會收到錯誤:NameError: name 'font_kanji' is not defined")

                (If I put global in front of font_Kanji and remove 'self.imp' in the .kv file I get the error: " NameError: name 'font_kanji' is not defined")

                推薦答案

                你的猜測是正確的:當你的按鈕被創建時,它的 imp 屬性是 None.解決這個問題的方法是觀察 imp 屬性并在其處理程序中設置 font_name 的值:

                Your guess is right: when your button is created its imp property is None. One to go around this would be to observe imp property and set the value of font_name in its handler:

                class FancyButton(Button):
                    imp = ObjectProperty(None)
                
                    def on_imp(self, obj, imp):
                        if imp:
                            self.font_name = imp.font_kanji
                

                這樣字體是在 imp 屬性用適當的 Important 實例初始化之后設置的.這種方法的缺點是Instance.font_kanji的變化不會觸發FancyButton.font_name的變化.

                This way the font is set after imp property is initialzied with proper Important instance. The dissadvantage of this method is that changes of Instance.font_kanji won't trigger changes of FancyButton.font_name.

                如果你想綁定兩個屬性,那么你必須從 Instance.font_kanji 端調用 bind 函數(因為我們想對其更改做出反應)以動態創建 FancyButton 實例:

                If you want to have both properties binded, then you have to call bind funtion from Instance.font_kanji side (since we want to react to its changes) for dynamically created FancyButton instances:

                class Important(StackLayout):
                    font_kanji = os.path.join('fonts', 'TakaoPMincho.ttf')
                
                    def NoInspiration(self, smile):
                        print("Received: {}".format(smile))
                
                    def AddFancy(self):
                        temp = FancyButton(text='f', imp = self)
                        self.bind(font_kanji=temp.setter('font_name'))
                        self.ids.boxy.add_widget(temp)
                

                kv語言定義的接口可以直接綁定:

                Interface defined in the kv language can do the binding directly:

                <Important>:
                    id: imp
                
                    BoxLayout:
                        id: boxy
                        orientation: 'vertical'
                
                        FancyButton:
                            text: "smiley"
                            font_name: root.font_kanji
                            imp: root
                
                        Button:
                            text: "add fancy"
                            on_release: imp.AddFancy()
                ''')
                

                這篇關于Kivy 外部規則繼承 2的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)

                  <bdo id='aK3Bd'></bdo><ul id='aK3Bd'></ul>
                • <small id='aK3Bd'></small><noframes id='aK3Bd'>

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

                        <tbody id='aK3Bd'></tbody>
                      <tfoot id='aK3Bd'></tfoot>
                    • <legend id='aK3Bd'><style id='aK3Bd'><dir id='aK3Bd'><q id='aK3Bd'></q></dir></style></legend>
                        1. 主站蜘蛛池模板: 精品产国自在拍 | 亚洲精品久久久 | 99精品久久| 精品一区二区三区四区视频 | 国产精品久久久久久久久久免费看 | 中文字幕成人av | 国产精品一区二区三区久久 | 99久9 | 国产一级片91 | 国产97碰免费视频 | 午夜精品久久久久久久99黑人 | 国产精品欧美一区二区三区 | 久久综合一区二区三区 | 国产高清视频在线观看 | 伊人伊成久久人综合网站 | 欧美成人性生活 | 九九热在线精品视频 | 亚洲精品一区二区三区四区高清 | 久久国产香蕉 | 欧美区在线 | 日韩久久在线 | 免费一区在线 | 欧美精品久久久 | 国产精品一区二区无线 | 亚洲免费观看视频网站 | 噜噜噜色网| 日韩欧美三区 | 成人国产精品久久久 | 91玖玖| 亚洲va国产日韩欧美精品色婷婷 | 国产成人精品一区二区三 | 久久国产精品久久久久 | 欧美日韩国产一区二区三区 | 99免费在线| 在线视频一区二区 | 日韩网站在线观看 | 欧美人妇做爰xxxⅹ性高电影 | 日韩精品免费一区二区在线观看 | 伦理二区 | 色偷偷噜噜噜亚洲男人 | 国产精品久久久久久久久久妞妞 |