[英]Kivy outside rule inherence
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 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) test.kv(工作)
#:kivy 1.9.0
<FancyButton@Button>:
on_release: self.parent.NoInspiration(':)')
<Important>:
id: imp
FancyButton:
text: "smiley"
BoxLayout:
Important
Received: :) 收到::)
test.kv ( not working) test.kv( 不工作)
#: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: 在第二个test.kv中,我在FancyButton前面添加了“ BoxLayout:”,然后突然出现错误:
AttributeError: 'BoxLayout' object has no attribute 'NoInspiration' AttributeError:“ BoxLayout”对象没有属性“ NoInspiration”
Change the kv to this 将kv更改为此
<FancyButton>:
on_release: self.imp.NoInspiration(':)')
<Important>:
id: imp
BoxLayout:
FancyButton:
text: "smiley"
imp: root
BoxLayout:
Important
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.