DESIGNING A ATTENDENCE SOFTWARE USING PYTHON AND KIVYMD FRAMEWORK
Imp Note -
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.
For this Program First Create a file by name Main.py and write python code in this file and then create a new file by name MainApp.kv and write kivy code in that file.
Following is the code of this Software :-
1. Code of Python program -
# Code of python Program
# A Python Program to create a Attendence Software using KIVYMD Frame work
from kivymd.app import MDApp
from kivymd.uix.list import MDList, IRightBodyTouch, OneLineAvatarIconListItem
from kivy.properties import StringProperty
from kivymd.uix.selectioncontrol import MDCheckbox
from kivy.core.window import Window
from kivymd.uix.boxlayout import BoxLayout
from kivymd.uix.label import MDLabel
Window.size = (370, 600)
class ContentNavigationDrawer(BoxLayout):
pass
class ClassesSelection(MDList):
"""This Class Create a list of classes on the main Screen"""
class Class9th(OneLineAvatarIconListItem):
""" This class add the item to particular list """
icon = StringProperty()
class Class10th(OneLineAvatarIconListItem):
""" This class add the item to particular list """
icon = StringProperty()
class Class11th(OneLineAvatarIconListItem):
""" This class add the item to particular list """
icon = StringProperty()
class Class12th(OneLineAvatarIconListItem):
""" This class add the item to particular list """
icon = StringProperty()
class RightCheckBox(MDCheckbox, IRightBodyTouch):
""" This class adds a Checkbox in the right of the list """
p_students_lst_9th = []
p_students_lst_10th = []
p_students_lst_11th = []
p_students_lst_12th = []
def p_students_9th(self, obj):
if self.active == True:
RightCheckBox.p_students_lst_9th.append(obj.text)
elif obj.text in RightCheckBox.p_students_lst_9th:
RightCheckBox.p_students_lst_9th.remove(obj.text)
def p_students_10th(self, obj):
if self.active == True:
RightCheckBox.p_students_lst_10th.append(obj.text)
elif obj.text in RightCheckBox.p_students_lst_10th:
RightCheckBox.p_students_lst_10th.remove(obj.text)
def p_students_11th(self, obj):
if self.active == True:
RightCheckBox.p_students_lst_11th.append(obj.text)
elif obj.text in RightCheckBox.p_students_lst_11th:
RightCheckBox.p_students_lst_11th.remove(obj.text)
def p_students_12th(self, obj):
if self.active == True:
RightCheckBox.p_students_lst_12th.append(obj.text)
elif obj.text in RightCheckBox.p_students_lst_12th:
RightCheckBox.p_students_lst_12th.remove(obj.text)
class Information(MDLabel):
pass
class MainApp(MDApp):
def __init__(self):
super().__init__()
self.students_name_class9th = ["yeshank", 'aditya', 'praveen', 'ritik', "nitesh", "Paresh", "zeeshan", "vivek",
"vibhuti", "kalua", "pelu", "tika", "malkhan"]
self.students_name_class10th = ["rohan", "mohan", "sohan", "tohan", "pohan", "chintu", "pintu", "rinku",
"tinku", 'linku', 'chandrabhan', "rajesh", "rakesh"]
self.students_name_class11th = ["harry", "mortal", "carry", "amit", "ashish", "alpha", "ajay", "Gaurav",
"sandeep", "Bhuvan", "sanjay", "nazim", "zayn", "elvish"]
self.students_name_class12th = ["munna", "bunty", "mahinder", "bahubali", "bhallaldev", "kattapa", "Rocky",
"keshav", "akshay", "sunny", "bobby", "jethalal", "Iyer"]
self.t_students_9th = 0
self.p_students_9th = 0
self.a_students_9th = 0
self.t_students_10th = 0
self.p_students_10th = 0
self.a_students_10th = 0
self.t_students_11th = 0
self.p_students_11th = 0
self.a_students_11th = 0
self.t_students_12th = 0
self.p_students_12th = 0
self.a_students_12th = 0
def class9th(self):
for name in self.students_name_class9th:
self.root.ids.data_class9th.add_widget(Class9th(text=name, icon="account"))
def class10th(self):
for name in self.students_name_class10th:
self.root.ids.data_class10th.add_widget(Class10th(text=name, icon="account"))
def class11th(self):
for name in self.students_name_class11th:
self.root.ids.data_class11th.add_widget(Class11th(text=name, icon="account"))
def class12th(self):
for name in self.students_name_class12th:
self.root.ids.data_class12th.add_widget(Class12th(text=name, icon="account"))
def save_data9th(self):
self.main()
self.root.ids.data_class9th.clear_widgets()
self.t_students_9th = len(self.students_name_class9th)
self.a_students_9th = self.t_students_9th - len(RightCheckBox.p_students_lst_9th)
self.p_students_9th = self.t_students_9th - self.a_students_9th
def save_data10th(self):
self.main()
self.root.ids.data_class10th.clear_widgets()
self.t_students_10th = len(self.students_name_class10th)
self.a_students_10th = self.t_students_10th - len(RightCheckBox.p_students_lst_10th)
self.p_students_10th = self.t_students_10th - self.a_students_10th
def save_data11th(self):
self.main()
self.root.ids.data_class11th.clear_widgets()
self.t_students_11th = len(self.students_name_class11th)
self.a_students_11th = self.t_students_11th - len(RightCheckBox.p_students_lst_11th)
self.p_students_11th = self.t_students_11th - self.a_students_11th
def save_data12th(self):
self.main()
self.root.ids.data_class12th.clear_widgets()
self.t_students_12th = len(self.students_name_class12th)
self.a_students_12th = self.t_students_12th - len(RightCheckBox.p_students_lst_12th)
self.p_students_12th = self.t_students_12th - self.a_students_12th
def move(self, obj):
self.root.ids.nav_drawer.set_state(new_state="close", animation=True)
if obj.text == "My Files":
self.root.ids.scrn_manager.current = "myfiles"
if obj.text == "About us":
self.root.ids.scrn_manager.current = "aboutus"
if obj.text == "Settings":
self.root.ids.scrn_manager.current = "settings"
def information(self, obj):
self.root.ids.scrn_manager.current = "info"
if obj.text == "Class - 9th":
if self.p_students_9th == 0 and self.p_students_9th == 0 and self.a_students_9th == 0:
self.root.ids.scroll.add_widget(Information(text="Take attendence", halign="center"))
else:
self.root.ids.scroll.add_widget(Information(text="Class - 9th", halign="center"))
self.root.ids.scroll.add_widget(Information(text=f"Total students = {self.t_students_9th}"))
self.root.ids.scroll.add_widget(Information(text=f"Present students = {self.p_students_9th}"))
self.root.ids.scroll.add_widget(Information(text=f"Absent Students = {self.a_students_9th}"))
self.root.ids.scroll.add_widget(Information(text="Present students list"))
i = 1
for name in RightCheckBox.p_students_lst_9th:
self.root.ids.scroll.add_widget(Information(text=f"{i} : {name}"))
i += 1
if obj.text == "Class - 10th":
if self.p_students_10th == 0 and self.p_students_10th == 0 and self.a_students_10th == 0:
self.root.ids.scroll.add_widget(Information(text="Take attendence", halign="center"))
else:
self.root.ids.scroll.add_widget(Information(text="Class - 10th", halign="center"))
self.root.ids.scroll.add_widget(Information(text=f"Total students = {self.t_students_10th}"))
self.root.ids.scroll.add_widget(Information(text=f"Present students = {self.p_students_10th}"))
self.root.ids.scroll.add_widget(Information(text=f"Absent Students = {self.a_students_10th}"))
self.root.ids.scroll.add_widget(Information(text="Present students list"))
i = 1
for name in RightCheckBox.p_students_lst_10th:
self.root.ids.scroll.add_widget(Information(text=f"{i} : {name}"))
i += 1
if obj.text == "Class - 11th":
if self.p_students_11th == 0 and self.p_students_11th == 0 and self.a_students_11th == 0:
self.root.ids.scroll.add_widget(Information(text="Take attendence", halign="center"))
else:
self.root.ids.scroll.add_widget(Information(text="Class - 11th", halign="center"))
self.root.ids.scroll.add_widget(Information(text=f"Total students = {self.t_students_11th}"))
self.root.ids.scroll.add_widget(Information(text=f"Present students = {self.p_students_11th}"))
self.root.ids.scroll.add_widget(Information(text=f"Absent Students = {self.a_students_11th}"))
self.root.ids.scroll.add_widget(Information(text="Present students list"))
i = 1
for name in RightCheckBox.p_students_lst_11th:
self.root.ids.scroll.add_widget(Information(text=f"{i} : {name}"))
i += 1
if obj.text == "Class - 12th":
if self.p_students_12th == 0 and self.p_students_12th == 0 and self.a_students_12th == 0:
self.root.ids.scroll.add_widget(Information(text="Take attendence", halign="center"))
else:
self.root.ids.scroll.add_widget(Information(text="Class - 12th", halign="center"))
self.root.ids.scroll.add_widget(Information(text=f"Total students = {self.t_students_12th}"))
self.root.ids.scroll.add_widget(Information(text=f"Present students = {self.p_students_12th}"))
self.root.ids.scroll.add_widget(Information(text=f"Absent Students = {self.a_students_12th}"))
self.root.ids.scroll.add_widget(Information(text="Present students list"))
i = 1
for name in RightCheckBox.p_students_lst_12th:
self.root.ids.scroll.add_widget(Information(text=f"{i} : {name}"))
i += 1
def build(self):
""" This Method Builds a App and Return that App """
return
def main(self):
self.root.ids.scrn_manager.current = "main"
def info_screen(self):
self.root.ids.scrn_manager.current = "myfiles"
self.root.ids.scroll.clear_widgets()
MainApp().run()
# Save It by .py extension
2. Code of KivyMD framework file
# Code of Kivy file
<ClassesSelection> :
OneLineIconListItem :
text : "Class - 9th"
on_press :
root.scrn_manager.current = "class9th"
app.class9th()
IconLeftWidget :
icon : "school"
OneLineIconListItem :
text : "Class - 10th"
on_press :
root.scrn_manager.current = "class10th"
app.class10th()
IconLeftWidget :
icon : "school"
OneLineIconListItem :
text : "Class - 11th"
on_press :
root.scrn_manager.current = "class11th"
app.class11th()
IconLeftWidget :
icon : "school"
OneLineIconListItem :
text : "Class - 12th"
on_press :
root.scrn_manager.current = "class12th"
app.class12th()
IconLeftWidget :
icon : "school"
<Class9th> :
IconLeftWidget :
icon : root.icon
RightCheckBox :
active : False
on_active : self.p_students_9th(root)
<Class10th> :
IconLeftWidget :
icon : root.icon
RightCheckBox :
on_active : self.p_students_10th(root)
<Class11th> :
IconLeftWidget :
icon : root.icon
RightCheckBox :
on_active : self.p_students_11th(root)
<Class12th> :
IconLeftWidget :
icon : root.icon
RightCheckBox :
on_active : self.p_students_12th(root)
<ContentNavigationDrawer> :
orientation : "vertical"
padding : 10
spacing : 10
AnchorLayout :
anchor_x : "left"
size_hint_y : None
height : avatar.height
Image :
id : avatar
source : 'kivy.png'
size_hint : None,None
size : 150,150
MDLabel :
text : "Yeshank Pawar"
font_size : 18
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "yeshankpawar14@gmail.com"
font_size : 18
size_hint_y : None
height : self.texture_size[1]
MDSeparator :
size_hint_y : None
height : 5
ScrollView :
MDList :
OneLineIconListItem :
text : "My Files"
on_press : app.move(self)
IconLeftWidget :
icon : "file"
OneLineIconListItem :
text : "About us"
on_press : app.move(self)
IconLeftWidget :
icon : "account"
OneLineIconListItem :
text : "Settings"
on_press : app.move(self)
IconLeftWidget :
icon : "settings"
OneLineIconListItem :
text : "Quit"
on_press : quit()
IconLeftWidget :
icon : "logout"
<Information> :
size_hint_y : None
height : self.texture_size[1]
font_size : 18
MDScreen :
NavigationLayout :
ScreenManager :
id : scrn_manager
MDScreen :
name : "main"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Class Selection"
left_action_items : [["menu", lambda x : nav_drawer.toggle_nav_drawer()]]
elevation : 11
ClassesSelection :
scrn_manager : scrn_manager
Widget :
MDScreen :
name : "class9th"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Class - 9th"
left_action_items : [["arrow-left", lambda x : app.main()]]
right_action_items : [["content-save", lambda x : app.save_data9th()]]
ScrollView
MDList :
id : data_class9th
MDScreen :
name : "class10th"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Class - 10th"
left_action_items : [["arrow-left", lambda x : app.main()]]
right_action_items : [["content-save", lambda x : app.save_data10th()]]
ScrollView
MDList :
id : data_class10th
MDScreen :
name : "class11th"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Class - 11th"
left_action_items : [["arrow-left", lambda x : app.main()]]
right_action_items : [["content-save", lambda x : app.save_data11th()]]
ScrollView
MDList :
id : data_class11th
MDScreen :
name : "class12th"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Class - 12th"
left_action_items : [["arrow-left", lambda x : app.main()]]
right_action_items : [["content-save", lambda x : app.save_data12th()]]
ScrollView :
MDList :
id : data_class12th
MDScreen :
name : "myfiles"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "My Files"
left_action_items : [["arrow-left",lambda x : app.main()]]
ScrollView :
MDList :
OneLineIconListItem :
text : "Class - 9th"
on_press : app.information(self)
IconLeftWidget :
icon : "information"
OneLineIconListItem :
text : "Class - 10th"
on_press : app.information(self)
IconLeftWidget :
icon : "information"
OneLineIconListItem :
text : "Class - 11th"
on_press : app.information(self)
IconLeftWidget :
icon : "information"
OneLineIconListItem :
text : "Class - 12th"
on_press : app.information(self)
IconLeftWidget :
icon : "information"
MDScreen :
name : "aboutus"
MDBoxLayout :
orientation : "vertical"
spacing : 15
MDToolbar :
title : "About us"
left_action_items : [["arrow-left",lambda x : app.main()]]
MDLabel :
text : "Developer name - Yeshank Pawar"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "Developed by - Python Developers ltd..."
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "Designer - Yeshank Pawar"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "MailID - yeshankpawar14@gmail.com"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "FacebookID - yeshankpawar14@gmail.com"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "YouTube - The Club of Python Developers"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
MDLabel :
text : "website - https://pythondevelopers14@blogspot.com"
font_size : 20
size_hint_y : None
height : self.texture_size[1]
Widget :
MDScreen :
name : "settings"
MDBoxLayout :
orientation : "vertical"
MDToolbar :
title : "Settings"
left_action_items : [["arrow-left",lambda x : app.main()]]
ScrollView :
MDScreen :
name : "info"
MDBoxLayout :
id : box
orientation : "vertical"
spacing : 15
MDToolbar :
title : "Information"
left_action_items : [["arrow-left",lambda x : app.info_screen()]]
ScrollView :
MDList :
id : scroll
MDNavigationDrawer :
id : nav_drawer
ContentNavigationDrawer :
# Save It by name MainApp.kv
Following are the images of the Software :-
1. This is the main Page of Software.
3. This is the main page with Navigation Drawer.
4. This is My files Pages where user can check the data of attendance of students
5. This is the Information page on which the information of students are displayed like total students, present students, Absent students and present students name.
6. This is About us page on which the Developers Information is displayed.
Great content, I'm a python developer, looking forward to start building mobile app using kivy, there is dearth of complete project tutorial on kivymd like yours, I appreciate effort put towards creating this.
ReplyDeletejust as advise, you should consider creating comprehensive course on kivymd with projects and step by step writing of code. you can sell the course on your website or udemy and likes
how to solve the traceback error in this code
ReplyDelete