How to delete tab / How to add close button to MDTabs

16 views
Skip to first unread message

Han Met

unread,
Jun 24, 2024, 8:31:06 PM (8 days ago) Jun 24
to Kivy users support
Hi everyone , I am new 

I am using kivymd ver. 2.0.1

MyRequests are:
1. How to delete tab from MDTabs
2. How to add close icon with tab name (like google chrome page).

this is my try:
plus_tab event is working but remove_tab event doesn't work.

from kivy.lang import Builder
from kivy.properties import StringProperty

from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.tab import (
    MDTabsItemIcon,
    MDTabsItemText,
    MDTabsItem,
)

KV='''
MDScreen:
    MDFloatLayout:
        md_bg_color: 1,0,0,.7
        size_hint: 1, .1
        pos_hint: {'x': 0, 'top': 1}

        MDButton:
            pos_hint: {'center_x': .3, 'center_y': .5}
            on_release:
                app.plus_tab()                
            MDButtonText:
                text: 'Add Tab'

        MDButton:
            pos_hint: {'center_x': .7, 'center_y': .5}
            on_release:
                app.remove_tab()
            MDButtonText:
                text: 'Remove Tab'

    MDTabsPrimary:
        id: tabs
        pos_hint: {"center_x": .5, "center_y": .8}        
        size_hint_x: .9
        allow_stretch: True
        label_only: True
        indicator_radius: [dp(10), dp(10), dp(10), dp(10)]
       
        MDDivider:

<Tab_Page>:

    MDTabsItemText:
        text: root.text

'''
class Tab_Page(MDTabsItem):
    text = StringProperty()

class Sample5(MDApp):

    def build(self):
        return Builder.load_string(KV)
    def plus_tab(self):
        self.root.ids.tabs.add_widget(Tab_Page(text='Wel'))

    def remove_tab(self):
        self.root.ids.tabs.remove_widget(Tab_Page(text='Wel'))


if __name__=='__main__':
    Sample5().run()

ELLIOT GARBUS

unread,
Jun 24, 2024, 10:43:12 PM (8 days ago) Jun 24
to Kivy users support
These features are not supported by KIvyMD.  My assumption is this is because these features are not part of the Google Material Design specifications that KivyMD seeks to implement.  

You can remove tabs in the Kivy TabbedPanel, and can add a close icon.  There is an example in the kivy-examples directory.  see: https://github.com/kivy/kivy/blob/master/examples/widgets/tabbed_panel_showcase.py




From: kivy-...@googlegroups.com <kivy-...@googlegroups.com> on behalf of Han Met <han...@gmail.com>
Sent: Monday, June 24, 2024 5:31 PM
To: Kivy users support <kivy-...@googlegroups.com>
Subject: [kivy-users] How to delete tab / How to add close button to MDTabs
 
--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/22bd8e70-2013-464c-a89f-8b3893cccc89n%40googlegroups.com.

Han Met

unread,
Jun 25, 2024, 8:29:39 AM (8 days ago) Jun 25
to kivy-...@googlegroups.com
Ok
Thank you for your reply.



--
B&R |
Hany Metwaly | Sales & Technical support      
0127-1646-519 | 0100-3560-512
Reply all
Reply to author
Forward
0 new messages