How to use kivymd custom class in different kivymd app

14 views Asked by At

this is my easymd.py


from kivymd.uix.card import MDCard 

from kivy.properties import ObjectProperty, BooleanProperty, StringProperty,ColorProperty



kv = '''

<SegmentedControl>:

    id: segment_panel

    size_hint_y: None

    height: self.minimum_height   

    md_bg_color:'red' if not self.segment_color else self.segment_color

<SegmentedControlItem>:

    id: s1

    text: ''

    color: 'black'

    size_hint_y: None

    height: self.minimum_height

    elevation: 0

    md_bg_color:'red'

    padding:20

        

    MDLabel:

        id: l1

        size_hint_y: None

        text: s1.text

        halign: 'center'

        color: s1.color

        pos_hint: {"center_y": .5}

        height: self.texture_size[1]

        

    MDSeparator:

        id: divider

        orientation: 'vertical'

        size_hint_y: None

        height: s1.height * 0.5

        pos_hint: {"center_y": .5}

        

'''

class SegmentedControl(MDCard):

        segment_color = ColorProperty(None)        

        pass



class SegmentedControlItem(MDCard):

        segment_color = ColorProperty(None)        

        active = BooleanProperty(True)

        pass



and this is my simple kivymd app. but It’s Just showing a blank MDCard. But i implemented so many things in my easymd's custom classes. You can see above


from kivymd.app import MDApp

from kivy.lang import Builder

from kivymd.theming import ThemeManager

from easymd import SegmentedControl,SegmentedControlItem



kv = '''



MDBoxLayout:

    orientation: 'vertical'

    md_bg_color:'pink'

    padding:20

    SegmentedControl:

        SegmentedControlItem:

            text:'Hello'





'''

class  Segment(SegmentedControl,SegmentedControlItem):

    '''implementing Segment'''

    

class SegmentSwapApp(MDApp):

    def build(self):

        return Builder.load_string(kv)



if __name__ == '__main__':

    SegmentSwapApp().run()

i want to use custom classes from my easymd.py But when i import classes and use them i only get a blank MDCard.I'm trying to find a solution but I'm unable. And also one thing to mention that i only make my custom class to be able to use the SegmentedControlItem under the SegmentedControl.

1

There are 1 answers

0
John Anderson On

You have defined rules for the SegmentedControlItem in your kv string in the easymd.py file, but you haven't done anything with that kv string. You can fix that by also importing that kv string and then loading it, like this:

from easymd import kv as kv3
Builder.load_string(kv3)