首页 > 代码库 > Kivy 自定义控件之(一)

Kivy 自定义控件之(一)


lableSlider1.kv文件 

<LabelSlider>:
orientation:‘vertical‘
BoxLayout:
MyLabelSlider:
name: ‘Slider1‘
onValue: root.onMySlider
id:mySlider
Label:
text:str(mySlider.ids.slider.value)
BoxLayout:
orientation:‘vertical‘
MyLabelSlider:
name: ‘slider2‘
MyLabelSlider:
name: ‘slider3‘
MyLabelSlider:
name: ‘slider4‘
MyLabelSlider:
name: ‘slider5‘


<MyLabelSlider@BoxLayout>:
name: ‘Slider‘
onValue: lambda value: print(‘MyLabelSlider no onValue function:‘,value)
Label:
text:root.name
Slider:
id:slider
on_value:root.onValue(self.value)


labelSlider.py文件 

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout


class LabelSlider(BoxLayout):
def onMySlider(self, value):
print(value)
pass

class LabelSlider1App(App):
def build(self):
return LabelSlider()


if __name__ == ‘__main__‘:
LabelSlider1App().run()


来自为知笔记(Wiz)


Kivy 自定义控件之(一)