Open In App

Python | Tabbed panel in kivy

Improve
Improve
Like Article
Like
Save
Share
Report

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

👉🏽 Kivy Tutorial – Learn Kivy with Examples.

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 functioning also.
9) return the widget/layout etc class
10) Run an instance of the class

Implementation Of Approach:

.py file




# 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()


.kv file




# .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???"))


Output:

Tab 1:

Tab 2:

Tab 3:



Last Updated : 18 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads