Kivy:继承另一个动态 类 值
Kivy: inherit another dynamic classes values
我有这样的动态 类:
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
对于我的一些CustomBoxLayout,我想添加一个canvas:before。
我可以创建一个新的动态 类 将两者的值结合起来,如下所示:
<BLChildren@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x + self.width*0.025, self.y
有没有办法 BLChildren
可以继承 BLMother
的所有值?
我使用 Kivy (1.10.1.dev0)
是的,BLChildren 可以继承BLMother 的所有值。详情请参考下面的例子。
示例 - 从 BLMother 继承
main.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class RootWidget(FloatLayout):
pass
class TestApp(App):
title = "With Inheritance of BLMother"
def build(self):
return RootWidget()
if __name__ == "__main__":
TestApp().run()
test.kv
#:kivy 1.10.0
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
<BLChildren@BoxLayout>:
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x + self.width*0.025, self.y
BLMother:
<RootWidget>:
BLChildren:
输出 - 从 BLMother 继承
我不知道你为什么把 pos = self.x + self.width*0.025, self.y 但是
给你:
-kv:
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
<BLChildren@BLMother>:
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x , self.y
BLChildren:
-py:
from kivy.app import App
class TestApp(App):
pass
if __name__ == "__main__":
TestApp().run()
我有这样的动态 类:
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
对于我的一些CustomBoxLayout,我想添加一个canvas:before。 我可以创建一个新的动态 类 将两者的值结合起来,如下所示:
<BLChildren@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x + self.width*0.025, self.y
有没有办法 BLChildren
可以继承 BLMother
的所有值?
我使用 Kivy (1.10.1.dev0)
是的,BLChildren 可以继承BLMother 的所有值。详情请参考下面的例子。
示例 - 从 BLMother 继承
main.py
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
class RootWidget(FloatLayout):
pass
class TestApp(App):
title = "With Inheritance of BLMother"
def build(self):
return RootWidget()
if __name__ == "__main__":
TestApp().run()
test.kv
#:kivy 1.10.0
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
<BLChildren@BoxLayout>:
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x + self.width*0.025, self.y
BLMother:
<RootWidget>:
BLChildren:
输出 - 从 BLMother 继承
我不知道你为什么把 pos = self.x + self.width*0.025, self.y 但是 给你:
-kv:
<BLMother@BoxLayout>:
orientation:"horizontal"
padding: 10, 0
spacing: 10
<BLChildren@BLMother>:
canvas.before:
Color:
rgba: 1, 1, 1, 0.8
Rectangle:
size: self.size
pos: self.x , self.y
BLChildren:
-py:
from kivy.app import App
class TestApp(App):
pass
if __name__ == "__main__":
TestApp().run()