Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behaviour of MDSegmentedButton #1690

Closed
Sahil-pixel opened this issue Apr 23, 2024 · 0 comments
Closed

Unexpected behaviour of MDSegmentedButton #1690

Sahil-pixel opened this issue Apr 23, 2024 · 0 comments
Labels
Type: Bug Bug report/Bug fix

Comments

@Sahil-pixel
Copy link

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

Screencast.from.23-04-24.04-04-26.PM.IST.mp4

Versions

  • OS: ubuntu
  • Python: 3.10
  • Kivy: 2.3.0
  • KivyMD: 2.0.1dev
@HeaTTheatR HeaTTheatR added the Type: Bug Bug report/Bug fix label Apr 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Bug report/Bug fix
Projects
None yet
Development

No branches or pull requests

2 participants