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

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

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

      1. Kivy 外部规则继承

        时间:2023-10-10
        <i id='SlEZl'><tr id='SlEZl'><dt id='SlEZl'><q id='SlEZl'><span id='SlEZl'><b id='SlEZl'><form id='SlEZl'><ins id='SlEZl'></ins><ul id='SlEZl'></ul><sub id='SlEZl'></sub></form><legend id='SlEZl'></legend><bdo id='SlEZl'><pre id='SlEZl'><center id='SlEZl'></center></pre></bdo></b><th id='SlEZl'></th></span></q></dt></tr></i><div id='SlEZl'><tfoot id='SlEZl'></tfoot><dl id='SlEZl'><fieldset id='SlEZl'></fieldset></dl></div>

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

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

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

              • <tfoot id='SlEZl'></tfoot>
                    <tbody id='SlEZl'></tbody>
                  本文介绍了Kivy 外部规则继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  I want to specify a special button so I don't have to adjust every button I use, however I want it's event to trigger a function in a different class.

                  main.py

                  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):
                  
                      def NoInspiration(self, smile):
                          print("Received: {}".format(smile))
                  
                  
                  class TestApp(App):
                      def build(self):
                          pass
                  
                  if __name__ == '__main__':
                      TestApp().run()
                  

                  test.kv (working)

                  #:kivy 1.9.0
                  
                  <FancyButton@Button>:
                      on_release: self.parent.NoInspiration(':)')
                  
                  
                  <Important>:
                      id: imp
                  
                      FancyButton:
                          text: "smiley"
                  
                  BoxLayout:
                      Important
                  

                  Received: :)

                  test.kv (not working)

                  #:kivy 1.9.0
                  
                  <FancyButton>:
                      on_release: self.parent.NoInspiration(':)')
                  
                  
                  <Important>:
                      id: imp
                  
                      BoxLayout:
                          FancyButton:
                              text: "smiley"
                  
                  BoxLayout:
                      Important
                  

                  In the 2nd test.kv I added 'BoxLayout:' in front of FancyButton and suddenly I get the error:

                  AttributeError: 'BoxLayout' object has no attribute 'NoInspiration'

                  Question

                  • Why does self.parent only refer to the direct parent and not < Important > in the 2nd example?
                  • How can I have on_release: in < FancyButton > point to the function NoInspiration() while keeping the function in < Important >?

                  Follow up questions

                  • Kivy rule inherence with add_widget()
                  • Kivy outside rule inherence 2

                  解决方案

                  Change the kv to this

                  <FancyButton>:
                      on_release: self.imp.NoInspiration(':)')
                  
                  
                  <Important>:
                      id: imp
                  
                      BoxLayout:
                          FancyButton:
                              text: "smiley"
                              imp: root
                  
                  BoxLayout:
                      Important
                  

                  这篇关于Kivy 外部规则继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Kivy 错误:属性错误:“无类型"对象没有属性“ 下一篇:Kivy-python:运行 Hello World 时出错

                  相关文章

                  最新文章

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

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

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