Python | Tabbed panel in kivy

Kivy is a platform independent GUI tool in Python. As it can be run on Android, IOS, linux and Windows etc. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktops applications

Tabbed panel

The TabbedPanel widget manages different widgets in tabs, with a header area for the actual tab buttons and a content area for showing the current tab content.

The TabbedPanel provides one default tab.



To use it must import :
from kivy.uix.tabbedpanel import TabbedPanel

Basic Approach:
1) import kivy
2) import kivy App
3) import floatlayout
4) import tabbedpanel
5) set minimum version(optional)
6) Create Tabbed panel class
7) create the App class
8) create .kv file:
       # create multiple tabs in it.
       # Do there functioninging also.
9) return the widget/layout etc class
10) Run an instance of the class

Implementation Of Approach:

.py file

filter_none

edit
close

play_arrow

link
brightness_4
code

# Program to explain how to create tabbed panel App in kivy  
       
# import kivy module     
import kivy   
         
# base Class of your App inherits from the App class.     
# app:always refers to the instance of your application    
from kivy.app import App  
       
# this restrict the kivy version i.e   
# below this kivy version you cannot   
# use the app or software   
kivy.require('1.9.0')  
  
# to  use this must have to import it
from kivy.uix.tabbedpanel import TabbedPanel
  
# Floatlayout allows us to place the elements
# relatively based on the current window
# size and height especially in mobiles
from kivy.uix.floatlayout import FloatLayout
  
# Create Tabbed class 
class Tab(TabbedPanel):
    pass
   
# create App class
class TabbedPanelApp(App):
    def build(self):
        return Tab()
  
# run the App
if __name__ == '__main__':
    TabbedPanelApp().run()

chevron_right


.kv file

filter_none

edit
close

play_arrow

link
brightness_4
code

# .kv file of tabbed panel
  
<Tab>:
  
    # creating the size
    # and the alignment of the tab 
    size_hint: .5, .5
    pos_hint: {'center_x': .5, 'center_y': .5}
    do_default_tab: False
  
    # Create tab 1
    TabbedPanelItem:
        text: 'Tab 1'
        Label:
            text: "First tab"
  
    # Create 2nd tab
    TabbedPanelItem:
        text: 'Tab 2'
        BoxLayout:
            Label:
                text: 'Press button'
            Button:
                text: 'Click it'
  
    # Create 3rd tab
    TabbedPanelItem:
        text: 'Tab 3'
        RstDocument:
            text: '\n'.join(("How are you GFG's???"))

chevron_right


Output:

Tab 1:

Tab 2:

Tab 3:



My Personal Notes arrow_drop_up

Competative Programmer

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.