Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kivy - Add an icon to tab buttons

I am using a TabbedPanel in Kivy, it works perfectly well, but I would like to customize the tab buttons a bit and add a icon next to the text.

Right now I have something like this : Current tab

And I would like something like that : Tab with icons

My kv file is as follows :

<KivyMasterPanel>
    do_default_tab: False
    id: MasterPanel
    tab_width: self.size[0]/len(self.tab_list)

    TabbedPanelItem:
        id: tab_A
        text: 'A'

    TabbedPanelItem:
        id: tab_B
        text: 'B'

    TabbedPanelItem:
        id: tab_C
        text: 'C'

Is there something I can use instead of TabbedPannelItem.text to put a BoxLayout or something inside. If possible I would like to be able to create my tabs using a kv file, but if it is not possible, no problem.

Thank you all in advance for your help.

like image 973
Clement Puech Avatar asked Nov 30 '25 16:11

Clement Puech


1 Answers

Make a custom TabbedPanelItem, where you'll add image background with Rectangle

<TPI@TabbedPanelItem>:
    canvas:
        Rectangle:
            source: <your_img>
            size: self.size
            pos: self.pos

and use the custom one instead of TabbedPanelItem in your KivyMasterPanel

like image 78
Peter Badida Avatar answered Dec 02 '25 06:12

Peter Badida



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!