In this video I’ll show you how to add tabs to your Kivy app.

Tabs are a really common design element in Graphical User Interfaces and Kivy makes using them really easy. In this video I’ll show you how to add tabs to your app, how to put things in the tabs, how to size the tabs, and how to position the tabs themselves (on top, bottom, left, or right).

Tabs are a great way to break apart the different elements of your GUI, and Kivy makes it pretty easy to use them.

Python Code: tabs.py
GitHub Code: tabs.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from kivy.uix.tabbedpanel import TabbedPanel


# Designate Our .kv design file 
Builder.load_file('tabs.kv')

class MyLayout(TabbedPanel):
	pass

class AwesomeApp(App):
	def build(self):
		return MyLayout()

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


Kivy Design Code: tabs.kv
GitHub Code: tabs.kv

<MyLayout>
	do_default_tab: False

	size_hint: .5, .5
	pos_hint: {'center_x': .5, 'center_y': .5}

        # ft_top, left_mid, left_bottom, top_left, 
        # top_mid, top_right, right_top, right_mid, 
        # right_bottom, bottom_left, bottom_mid, 
        # bottom_right.
    
	tab_pos: 'left_top'

	TabbedPanelItem:
		text: "Tab 1"
		Label:
			text: "Hello World!"

	TabbedPanelItem:
		text: "Tab 2"
		BoxLayout:
			Label:
				text: "Press The Button =>"
			Button:
				text: "Click Me!!"

	TabbedPanelItem:
		text: "Tab 3"

		Image:
			source: "images/aspen1.jpg"


		

John Elder

John is the CEO of Codemy.com where he teaches over 100,000 students how to code! He founded one of the Internet's earliest advertising networks and sold it to a publicly company at the height of the first dot com boom. After that he developed the award-winning Submission-Spider search engine submission software that's been used by over 3 million individuals, businesses, and governments in over 42 countries. He's written several Amazon #1 best selling books on coding, and runs a popular Youtube coding channel.

View all posts

Add comment

Your email address will not be published. Required fields are marked *

John Elder