CREATING TOOLBAR(Top) USING KIVYMD
Link of Video on Youtube - https://youtu.be/wbSliTPE4pg
Following are the steps that are required to create Toolbar :
1. Creating the App by importing the MDApp class of kivymd module.2. Creating the Box Layout by using MDBoxLayout class of kivymd module.3. Creating Toolbar using MDToolbar class of kivymd module.
First Create a Python file (extension .py) then, create a kivy file (.kv extension) name of kivy file should be same as app name.
App name is the name of the class that consist of build function and created by inheriting the MDApp class
Following is the list of attributes used in this program :-
Attributes of MDBoxLayout class1. md_bg_color - To change the background color (Takes values in RGB format).2. orientation - To change the orientation of items of box layout (Takes values vertical and horizontal).
Attributes of MDToolbar class1. title - Title of Toolbar (Takes string).2. left_action_items - To add the items which is on the left side of the toolbar (Takes values in list type).
Ex. left_action_item : [["menu" , lambda x : print("menu button is pressed"]]In the Above Example menu is icon name and lambda x : print("Menu button is pressed") is the action to be performed when the button is pressed which is given using lambda function.
3. right_action_items - To add the items which is on the right side of the toolbar (Takes values in list type (same as left_action_items)).4. size_hint_y - To change the size of toolbar according to y axis (Takes values of float type and None).5. height - To change the height of toolbar (Takes numeric values).6. md_bg_color - To change the background color of Toolbar (Takes vaues in RGB format) .7. specific_text_color - To change the text color of Toolbar (Takes values in RGB format).8. elevation - To make the shadow of toolbar (Takes numeric values).
Following is the code of this program :-
1. Code of Python program (Save it by .py extension)
from kivymd.app import MDApp
class Myapp(MDApp): def build(self): return
Myapp().run()
2. Code of Kivy program (Save it by name Myapp.kv)
MDBoxLayout : orientation : "vertical" MDToolbar : title : "Toolbar" left_action_items : [["menu" , lambda x : print("Menu Button is Pressed")]] right_action_items : [["dots-vertical" , lambda x : print("vertical Dots are pressed")]] elevation : 12 MDLabel : text : "Contents" halign : "center"
1. Code of Python program (Save it by .py extension)
from kivymd.app import MDApp
class Myapp(MDApp):
def build(self):
return
Myapp().run()
2. Code of Kivy program (Save it by name Myapp.kv)
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Toolbar"
left_action_items : [["menu" , lambda x : print("Menu Button is Pressed")]]
right_action_items : [["dots-vertical" , lambda x : print("vertical Dots are pressed")]]
elevation : 12
MDLabel :
text : "Contents"
halign : "center"
Comments
Post a Comment