In this article, we will see how to add the toolbar in mobile applications using KivyMD in Python. KivyMD provide two type of toolbar -
- Top Toolbar
- Bottom Toolbar
Let's see how to create each type of toolbar and how to add certain attributes like title, left menu, right menu, etc. Some commonly used attributes are -
Adding Title:
To add a title to the toolbar use the title attribute.
Syntax: title: 'The title we want to show on the toolbar'
It is represented as follows-
MDToolbar:
title:'Demo'

Adding Left and Right menu:
It is the left and the right menu that you must have seen in certain apps. To create this the following attributes are used.
Syntax:
Left_action_items: we need to specify a icon and function associated with it that will show on the left side of title.
right_action_items: similar to left_action_items but on the right side
It is represented as follows:
MDToolbar:
title:'Demo'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
right_action_items:[['logout',lambda x: app.navigation_draw()]]

Elevation:
It is used for showing shadow effect below a toolbar
Syntax: elevation: to show a shadow effect below toolbar
It is represented as follows
MDToolbar:
title:'Demo'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
right_action_items:[['logout',lambda x: app.navigation_draw()]]
elevation:10

Background Color:
To change the color of the toolbar md_bg_color is used.
Syntax: md_bg_color: Its representation should be an RGB value
It is represented as follows:
MDToolbar:
title:'Demo'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
right_action_items:[['logout',lambda x: app.navigation_draw()]]
elevation:10
md_bg_color: 0,0,100/255,1

Bottom Bar:
In addition to the top toolbar, we can also add a bottom toolbar. MDBottomAppBar is used to display the toolbar at the bottom.
It is represented as follows:
MDBottomAppBar:
MDToolbar:
title:'Bottom'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
elevation:10
md_bg_color: 0,0,100/255,1
Let's see an example where we will create both the top and bottom toolbar.
Note: The widgets on the screen will adjust themselves according to the size of the window because widgets use size hinting (adjustment) by default.
Python3
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import Screen
from kivy.lang import Builder
# builder method
helper="""
Screen:
name:'About us'
BoxLayout:
orientation:'vertical'
MDToolbar:
title:'Demo'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
right_action_items:[['logout',lambda x: app.navigation_draw()]]
elevation:10
md_bg_color: 0,0,100/255,1
MDLabel:
text:"hi"
halign:'center'
MDBottomAppBar:
MDToolbar:
title:'Bottom'
left_action_items:[['menu',lambda x: app.navigation_draw()]]
elevation:10
md_bg_color: 0,0,100/255,1
"""
class Demo(MDApp):
def build(self):
screen=Builder.load_string(helper)
return screen
# lambda Function
def navigation_draw(self):
print("NavBar")
if __name__ == "__main__":
Demo().run()
Output:
Similar Reads
How to Create banner in kivymd-Python?
In this article, we will see how to add the banner to our application using KivyMD in Python. A banner is a dropdown item when a button or action is triggered. Banners are widely used for pop-ups and warnings in mobile applications. You might need a basic understanding of kv lang to get started. Ins
5 min read
How to Create Checkbox in Kivymd-Python
In this article, we will see how to add the Check box in our application using KivyMD in Python. KivyMD is a collection of Material Design compliant widgets which can be used with Kivy. Installation: To install these modules type the below command in the terminal. pip install kivy pip install kivym
3 min read
Fonts in Kivymd-Python
In this article, we will develop a GUI window using kivy framework of Python. Kivy is a platform-independent GUI tool in Python. It is an open-source Python library for the rapid development of multi-touch applications on Windows, macOS, Android, iOS, Linux, and Raspberry Pi. KivyMD package is a col
5 min read
Python - Create multiple toolbars in wxPython
As we created a single toolbar in our previous article we are now going to learn how can we create multiple toolbars in wxPython. So we are going to create two toolbars and add tools to both of them. Steps :1. Create a vertical sizer. 2. Create first toolbar. 3. Add tools to first toolbar. 2. Create
1 min read
Python| AnchorLayout 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. 👉🏽 Kivy Tutorial - Learn Kivy with Examples. Anc
3 min read
Create spinner using KivyMD
In this article, we will learn how to create a spinner using KivyMD in Python programming language. Create spinner using KivyMD In addition to the Kivy framework is KivyMD. A set of Material Design widgets for use with the Kivy GUI framework which is used to create mobile applications. The Kivy fram
4 min read
Python | Canvas 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. ???????? Kivy Tutorial - Learn Kivy with Examples. Canvas: The
4 min read
wxPython | CreateTool() function in wx.Toolbar
In this particular article we are going to learn about CreateTool() function in wx.ToolBar class in wxPython. CreateTool() function is a factory function to create a new toolbar tool. CreateTool() function only creates a tool which is further added using AddTool() function. Syntax: wx.ToolBar.Create
2 min read
Hello World in Kivy
Kivy is an opensource multi-platform GUI development library for Python and can run on iOS, Android, Windows, OS X, and GNU/Linux. It helps develop applications that make use of innovative, multi-touch UI. The fundamental idea behind Kivy is to enable the developer to build an app once and use it ac
2 min read
GridLayouts in Kivy | Python
Kivy is a platform independent as it can be run on Android, IOS, Linux and Windows, etc. Kivy provides you the functionality to write the code for once and run it on different platforms. It is basically used to develop the Android application, but it does not mean that it can not be used on Desktop
3 min read