def build(self):
return Builder.load_string("""
BoxLayout:
orientation:'vertical'
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle disabled"
color: [0,0,0,1]
CheckBox:
on_press: slider.disabled = not slider.disabled
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle active"
color: [0,0,0,1]
CheckBox:
on_press: slider.active = not slider.active
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle show off"
color: [0,0,0,1]
CheckBox:
on_press: slider.show_off = not slider.show_off
MDSlider:
id:slider
min:0
max:100
value: 40
MDSlider:
id:slider2
orientation:"vertical"
min:0
max:100
value: 40
""")
python类load_string()的实例源码
def build(self):
Clock.schedule_interval(self.callback, 1)
return Builder.load_string("""#:import MDSlider kivymd.slider.MDSlider
#:import MDLabel kivymd.label.MDLabel
BoxLayout:
orientation:'vertical'
padding: '8dp'
MDSlider:
id:slider
min:0
max:100
value: 10
MDProgressBar:
value: app.rvalue
rgbr:"00FF00"
MDProgressBar:
reversed: True
value: app.rvalue
rgbr:"00FFFF"
BoxLayout:
MDProgressBar:
orientation:"vertical"
reversed: False
value: slider.value
rgbr:"FFFF00"
test: True
alpha:.7
MDProgressBar:
orientation:"vertical"
value: slider.value
reversed:True
rgbr:"00ff77"
MDLabel:
text: str(app.rvalue)
theme_text_color: 'Primary'
font_style:"Caption"
size_hint_y: None
halign: 'center'
height: self.texture_size[1] + dp(64)
""")
def build(self):
return Builder.load_string("""
BoxLayout:
orientation:'vertical'
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle disabled"
color: [0,0,0,1]
CheckBox:
on_press: slider.disabled = not slider.disabled
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle active"
color: [0,0,0,1]
CheckBox:
on_press: slider.active = not slider.active
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle show off"
color: [0,0,0,1]
CheckBox:
on_press: slider.show_off = not slider.show_off
MDSlider:
id:slider
min:0
max:100
value: 40
MDSlider:
id:slider2
orientation:"vertical"
min:0
max:100
value: 40
""")
def build(self):
# self.theme_cls.primary_palette = 'Indigo'
return Builder.load_string("""
#:import MDLabel kivymd.label.MDLabel
BoxLayout:
spacing: '64dp'
MDAccordion:
orientation: 'vertical'
MDAccordionItem:
title: 'Item 1'
icon: 'home'
MDAccordionSubItem:
text: "Subitem 1"
MDAccordionSubItem:
text: "Subitem 2"
MDAccordionSubItem:
text: "Subitem 3"
MDAccordionItem:
title: 'Item 2'
icon: 'earth'
MDAccordionSubItem:
text: "Subitem 4"
MDAccordionSubItem:
text: "Subitem 5"
MDAccordionSubItem:
text: "Subitem 6"
MDAccordionItem:
title: 'Item 3'
MDAccordionSubItem:
text: "Subitem 7"
MDAccordionSubItem:
text: "Subitem 8"
MDAccordionSubItem:
text: "Subitem 9"
MDAccordion:
orientation: 'horizontal'
MDAccordionItem:
title:'Item 1'
icon: 'home'
MDLabel:
text:'Content 1'
theme_text_color:'Primary'
MDAccordionItem:
title:'Item 2'
MDLabel:
text:'Content 2'
theme_text_color:'Primary'
MDAccordionItem:
title:'Item 3'
MDLabel:
text:'Content 3'
theme_text_color:'Primary'
""")
def build(self):
return Builder.load_string("""
BoxLayout:
orientation:'vertical'
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle disabled"
color: [0,0,0,1]
CheckBox:
on_press: slider.disabled = not slider.disabled
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle active"
color: [0,0,0,1]
CheckBox:
on_press: slider.active = not slider.active
BoxLayout:
size_hint_y:None
height: '48dp'
Label:
text:"Toggle show off"
color: [0,0,0,1]
CheckBox:
on_press: slider.show_off = not slider.show_off
MDSlider:
id:slider
min:0
max:100
value: 40
MDSlider:
id:slider2
orientation:"vertical"
min:0
max:100
value: 40
""")