kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.21k stars 663 forks source link

Unexpected behaviour of MDSegmentedButton #1690

Closed Sahil-pixel closed 4 months ago

Sahil-pixel commented 5 months ago

I am adding and removing widgets MDSegmentedButtonItem by button press but outcome is not as expected . MDSegmentedButtonItem increases its size , see video

Code and Logs


from kivymd.uix.label import MDLabel
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.screen import MDScreen
from kivymd.uix.segmentedbutton import (
    MDSegmentedButton,
    MDSegmentedButtonItem,
    MDSegmentButtonLabel,
)
from kivymd.app import MDApp

KV = '''
<MS>:
    md_bg_color: self.theme_cls.backgroundColor

    MDBoxLayout:
        id: box
        orientation: "vertical"
        size_hint_x: .7
        adaptive_height: True
        spacing: "24dp"
        pos_hint: {"center_x": .5, "center_y": .5}
        MDSegmentedButton:
            id:sb
        Button:
            text:'Add Items'
            size_hint:None,None
            pos_hint:{'x':0,'y':0}
            size:'80dp','48dp'
            on_release:root._add()
        Button:
            text:'Remove Items'
            size_hint:None,None
            size:'80dp','48dp'
            pos_hint:{'right':1,'y':0}
            on_release:root._remove()
'''

Builder.load_string(KV)
class MS(MDScreen):
    items=[]
    def _add(self):
        self.items=[]
        for i in range(4):
            item=MDSegmentedButtonItem(MDSegmentButtonLabel(text="Albums",),on_active=lambda x:print(x),)
            self.items.append(item)
            self.ids.sb.add_widget(item)

    def _remove(self):
        print('hello')

        for item in self.items:
            print(item)
            self.ids.sb.ids.container.remove_widget(item)

class Example(MDApp):

    def build(self):
        return MS()

Example().run()

Screenshots

Add images to explain u

https://github.com/kivymd/KivyMD/assets/57060638/deeb704d-008f-41c1-beed-7f64d8d363a9

Versions