from kivy.uix.label import Label
from kivy.uix.scrollview import ScrollView
from kivy.uix.boxlayout import BoxLayout
from kivy.lang import Builder
from kivy.base import runTouchApp
from kivy.properties import StringProperty
from kivy.properties import ListProperty
from kivy.graphics.vertex_instructions import Rectangle
from kivy.graphics.context_instructions import Color
Builder.load_string('''
<bbx>:
orientation: 'vertical'
my2App:
color: 1,0,0,1
<my2App>:
text: root.text
Label:
text: root.text
font_size: 16
size_hint_y: None
text_size: self.width, None
height: self.texture_size[1]
canvas:
Color:
rgba: root.color
Rectangle:
pos: self.pos
size: self.size
''')
class my2App(ScrollView):
text = StringProperty('default string'*200)
color = ListProperty([1,0,0,0.25])
class bbx(BoxLayout):
pass
runTouchApp(bbx())
这是我练习的kivy代码。my2App是一个用户定义的小部件,主要是从本教程(https://www.youtube.com/watch?v=WdcUg_rX2fM)中复制的。唯一添加的是ListProperty定义的color属性。不知怎的,这个用户定义的颜色属性没有成功。我试着运行my2App,但也没用。在
^{pr2}$
Widget名称必须以大写字母开头才能使用kv,因为它使用大写字母来区分它们和属性。这里,它认为
my2app:
是一个属性设置。在相关问题 更多 >
编程相关推荐