Material App
Description
KV = ''' MDScreen: MDLabel: text: 'Hello, World!' halign: 'center' ''' from kivy.lang import Builder from kivymd.app import MDApp class MainApp(MDApp): def build(self): return Builder.load_string(KV) def on_start(self): self.fps_monitor_start() MainApp().run()
ID:(13916, 0)
MDLabel
Description
MDLabel
MDLabel format:
MDLabel: text: 'Custom color' halign: 'center' theme_text_color: 'Custom' text_color: 0, 0, 1, 1
No special library, no append of widget.
Example in code
from kivy.lang import Builder from kivymd.app import MDApp KV = ''' MDScreen: MDBoxLayout: orientation: 'vertical' MDToolbar: title: 'MDLabel' MDLabel: text: 'MDLabel' ''' class MainApp(MDApp): def build(self): return Builder.load_string(KV) MainApp().run()
ID:(13935, 0)
MDList
Description
MDList
MDList format:
MDList: id: container
No special library, no append of widget.
Example in code
from kivy.lang import Builder from kivymd.app import MDApp KV = ''' ScrollView: MDList: OneLineAvatarIconListItem: on_release: print('Click!') IconLeftWidget: icon: 'github' OneLineAvatarIconListItem: on_release: print('Click 2!') IconLeftWidget: icon: 'gitlab' ''' class MainApp(MDApp): def build(self): return Builder.load_string(KV) MainApp().run()
ID:(13928, 0)
MDList, Icon and Checkbox
Description
MDList, Icon and Checkbox
MDList format:
KV = ''' <ListItemWithCheckbox>: IconLeftWidget: icon: root.icon RightCheckbox: BoxLayout: ScrollView: MDList: id: scroll ''' class ListItemWithCheckbox(OneLineAvatarIconListItem): '''Custom list item.''' icon = StringProperty('android') class RightCheckbox(IRightBodyTouch, MDCheckbox): '''Custom right container.'''
Special libraries:
- from kivy.properties import StringProperty
- from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem
- from kivymd.uix.selectioncontrol import MDCheckbox
- from kivymd.icon_definitions import md_icons
Example in code
from kivy.lang import Builder from kivy.properties import StringProperty from kivymd.app import MDApp from kivymd.uix.list import IRightBodyTouch, OneLineAvatarIconListItem from kivymd.uix.selectioncontrol import MDCheckbox from kivymd.icon_definitions import md_icons KV = ''' <ListItemWithCheckbox>: IconLeftWidget: icon: root.icon RightCheckbox: BoxLayout: ScrollView: MDList: id: scroll ''' class ListItemWithCheckbox(OneLineAvatarIconListItem): '''Custom list item.''' icon = StringProperty('android') class RightCheckbox(IRightBodyTouch, MDCheckbox): '''Custom right container.''' class MainApp(MDApp): def build(self): return Builder.load_string(KV) def on_start(self): icons = list(md_icons.keys()) for i in range(30): self.root.ids.scroll.add_widget( ListItemWithCheckbox(text=f'Item {i}', icon=icons[i]) ) MainApp().run()
ID:(13929, 0)
MDDataTable
Description
MDDataTable
MDDataTable format:
MDDataTable( use_pagination=True, check=True, column_data=[('No.', dp(30)), ('Status', dp(30)), ('Signal Name', dp(60), self.sort_on_signal), ('Severity', dp(30)), ('Stage', dp(30)), ('Schedule', dp(30), self.sort_on_schedule), ('Team Lead', dp(30), self.sort_on_team),], row_data=[('1',('alert', [255 / 256, 165 / 256, 0, 1], 'No Signal'),'Astrid: NE shared managed','Medium','Triaged','0:33','Chase Nguyen',), ('2',('alert-circle', [1, 0, 0, 1], 'Offline'),'Cosmo: prod shared ares','Huge','Triaged','0:39','Brie Furman',), ('3',('checkbox-marked-circle',[39 / 256, 174 / 256, 96 / 256, 1],'Online',),'Phoenix: prod shared lyra-lists','Minor','Not Triaged','3:12','Jeremy lake',), ('4',('checkbox-marked-circle',[39 / 256, 174 / 256, 96 / 256, 1],'Online',),'Sirius: NW prod shared locations','Negligible','Triaged','13:18','Angelica Howards',), ('5',('checkbox-marked-circle',[39 / 256, 174 / 256, 96 / 256, 1],'Online',),'Sirius: prod independent account','Negligible','Triaged','22:06','Diane Okuma',),], sorted_on='Schedule', sorted_order='ASC', elevation=2,)
Special libraries:
- from kivy.metrics import dp
- from kivymd.uix.datatables import MDDataTable
- from kivymd.uix.screen import MDScreen
Example in code
from kivy.metrics import dp from kivymd.app import MDApp from kivymd.uix.datatables import MDDataTable from kivymd.uix.screen import MDScreen class MainApp(MDApp): def build(self): self.data_tables = MDDataTable( use_pagination=True, check=True, column_data=[ ('No.', dp(30)), ('Status', dp(30)), ('Signal Name', dp(60), self.sort_on_signal), ('Severity', dp(30)), ('Stage', dp(30)), ('Schedule', dp(30), self.sort_on_schedule), ('Team Lead', dp(30), self.sort_on_team), ], row_data=[ ( '1', ('alert', [255 / 256, 165 / 256, 0, 1], 'No Signal'), 'Astrid: NE shared managed', 'Medium', 'Triaged', '0:33', 'Chase Nguyen', ), ( '2', ('alert-circle', [1, 0, 0, 1], 'Offline'), 'Cosmo: prod shared ares', 'Huge', 'Triaged', '0:39', 'Brie Furman', ), ( '3', ( 'checkbox-marked-circle', [39 / 256, 174 / 256, 96 / 256, 1], 'Online', ), 'Phoenix: prod shared lyra-lists', 'Minor', 'Not Triaged', '3:12', 'Jeremy lake', ), ( '4', ( 'checkbox-marked-circle', [39 / 256, 174 / 256, 96 / 256, 1], 'Online', ), 'Sirius: NW prod shared locations', 'Negligible', 'Triaged', '13:18', 'Angelica Howards', ), ( '5', ( 'checkbox-marked-circle', [39 / 256, 174 / 256, 96 / 256, 1], 'Online', ), 'Sirius: prod independent account', 'Negligible', 'Triaged', '22:06', 'Diane Okuma', ), ], sorted_on='Schedule', sorted_order='ASC', elevation=2, ) self.data_tables.bind(on_row_press=self.on_row_press) self.data_tables.bind(on_check_press=self.on_check_press) screen = MDScreen() screen.add_widget(self.data_tables) return screen def on_row_press(self, instance_table, instance_row): '''Called when a table row is clicked.''' print(instance_table, instance_row) def on_check_press(self, instance_table, current_row): '''Called when the check box in the table row is checked.''' print(instance_table, current_row) # Sorting Methods: # since the https://github.com/kivymd/KivyMD/pull/914 request, the # sorting method requires you to sort out the indexes of each data value # for the support of selections. # # The most common method to do this is with the use of the builtin function # zip and enumerate, see the example below for more info. # # The result given by these funcitons must be a list in the format of # [Indexes, Sorted_Row_Data] def sort_on_signal(self, data): return zip(*sorted(enumerate(data), key=lambda l: l[1][2])) def sort_on_schedule(self, data): return zip( *sorted( enumerate(data), key=lambda l: sum( [ int(l[1][-2].split(':')[0]) * 60, int(l[1][-2].split(':')[1]), ] ), ) ) def sort_on_team(self, data): return zip(*sorted(enumerate(data), key=lambda l: l[1][-1])) MainApp().run()
ID:(13923, 0)
MDExpansionPanel
Description
MDExpansionPanel
MDExpansionPanel format:
<Content> adaptive_height: True TwoLineIconListItem: text: '(050)-123-45-67' secondary_text: 'Mobile' IconLeftWidget: icon: 'phone'
Special libraries:
- from kivymd.uix.boxlayout import MDBoxLayout
- from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine
- from kivymd import images_path
Example in code
from kivy.lang import Builder from kivymd.app import MDApp from kivymd.uix.boxlayout import MDBoxLayout from kivymd.uix.expansionpanel import MDExpansionPanel, MDExpansionPanelThreeLine from kivymd import images_path KV = ''' <Content> adaptive_height: True TwoLineIconListItem: text: '(050)-123-45-67' secondary_text: 'Mobile' IconLeftWidget: icon: 'phone' ScrollView: MDGridLayout: id: box cols: 1 adaptive_height: True ''' class Content(MDBoxLayout): '''Custom content.''' class MainApp(MDApp): def build(self): return Builder.load_string(KV) def on_start(self): for i in range(10): self.root.ids.box.add_widget( MDExpansionPanel( icon=f'{images_path}kivymd.png', content=Content(), panel_cls=MDExpansionPanelThreeLine( text='Text', secondary_text='Secondary text', tertiary_text='Tertiary text', ) ) ) MainApp().run()
ID:(13934, 0)
MDCard
Description
MDCard
MDCard format:
MDCard: orientation: 'vertical' padding: '8dp' size_hint: None, None size: '280dp', '180dp' pos_hint: {'center_x': .5, 'center_y': .5} MDLabel: text: 'Title' theme_text_color: 'Secondary' adaptive_height: True MDSeparator: height: '1dp' MDLabel: text: 'Body'
No special library, no append of widget.
Example in code
from kivy.lang import Builder from kivymd.app import MDApp KV = ''' MDScreen: MDCard: orientation: 'vertical' padding: '8dp' size_hint: None, None size: '280dp', '180dp' pos_hint: {'center_x': .5, 'center_y': .5} MDLabel: text: 'Title' theme_text_color: 'Secondary' adaptive_height: True MDSeparator: height: '1dp' MDLabel: text: 'Body' ''' class MainApp(MDApp): def build(self): return Builder.load_string(KV) MainApp().run()
ID:(13962, 0)
MDProgressBar
Description
MDProgressBar
MDProgressBar format:
MDProgressBar: value: 50
No special library, no append of widget.
Example in code
from kivy.lang import Builder from kivymd.app import MDApp KV = ''' MDBoxLayout: padding: '10dp' MDProgressBar: value: 50 ''' class Test(MDApp): def build(self): return Builder.load_string(KV) Test().run()
ID:(13932, 0)
MDBackdrop
Description
MDBackdrop
Example:
from kivy.lang import Builder from kivymd.uix.screen import MDScreen from kivymd.app import MDApp # Your layouts. Builder.load_string( ''' #:import Window kivy.core.window.Window #:import IconLeftWidget kivymd.uix.list.IconLeftWidget <ItemBackdropFrontLayer@TwoLineAvatarListItem> icon: 'android' IconLeftWidget: icon: root.icon <MyBackdropFrontLayer@ItemBackdropFrontLayer> backdrop: None text: 'Lower the front layer' secondary_text: ' by 50 %' icon: 'transfer-down' on_press: root.backdrop.open(-Window.height / 2) pos_hint: {'top': 1} _no_ripple_effect: True <MyBackdropBackLayer@Image> size_hint: .8, .8 source: 'data/logo/kivy-icon-512.png' pos_hint: {'center_x': .5, 'center_y': .6} ''' ) # Usage example of MDBackdrop. Builder.load_string( ''' <ExampleBackdrop> MDBackdrop: id: backdrop left_action_items: [['menu', lambda x: self.open()]] title: 'Example Backdrop' radius_left: '25dp' radius_right: '0dp' header_text: 'Menu:' MDBackdropBackLayer: MyBackdropBackLayer: id: backlayer MDBackdropFrontLayer: MyBackdropFrontLayer: backdrop: backdrop ''' ) class ExampleBackdrop(MDScreen): pass class MainApp(MDApp): def __init__(self, **kwargs): super().__init__(**kwargs) def build(self): return ExampleBackdrop() MainApp().run()
ID:(13926, 0)