Student Management System Using Python

Student Management System Using Python ​

Introduction:

The Student Management System is a comprehensive software solution designed to streamline the process of managing student records in educational institutions. This project aims to provide a user-friendly interface for administrators and educators to efficiently handle student information, including personal details, class assignments, admission dates, payment records, and more.

With the increasing complexity of educational administration, there arises a need for a robust system to centralize and organize student data effectively. The Student Management System addresses this need by offering a feature-rich platform that facilitates tasks such as enrollment, record-keeping, communication, and analysis.

Key Features:

  1. User-friendly Interface: The system features an intuitive graphical interface built using the Tkinter library in Python, ensuring ease of use for administrators and educators.

  2. Database Integration: Utilizing SQLite, the system stores and manages student data in a structured manner, enabling efficient retrieval and manipulation of information.

  3. Student Record Management: Administrators can add, update, delete, and search for student records, including personal details, class assignments, and admission dates.

  4. Payment Tracking: The system allows tracking of payment records, enabling administrators to monitor fee payments on a monthly basis.

  5. Customizable Reporting: Educators can generate customized reports to analyze student performance, attendance, and payment history, aiding in informed decision-making.

  6. Error Handling and Validation: The system incorporates robust error handling mechanisms and data validation checks to ensure data integrity and minimize errors.

Required modules:

  1. tkinter: This module is a standard GUI (Graphical User Interface) library in Python, used for creating GUI applications.

  2. sqlite3: This module enables interaction with SQLite databases, allowing the project to store and manage student data.

  3. messagebox: This module provides a simple way to display messages in a dialog box, which is useful for showing error messages or notifications to the user.

Code Explanation:

  1. Importing Modules:

    from tkinter import *
    from tkinter import ttk
    import sqlite3
    from tkinter import messagebox
    
    • The code imports necessary modules:
      • tkinter: This is a standard GUI (Graphical User Interface) library in Python.
      • sqlite3: This module enables interaction with SQLite databases.
      • messagebox: This module provides a simple way to display messages in a dialog box.
  2. Creating a Class Student:

     
    class Student:
        def __init__(self, root):
            # Constructor function where the GUI is defined
    
    • The Student class is created to manage the student management system application.
    • The __init__ method initializes the attributes of the class and creates the GUI elements.
  3. Initializing the Tkinter GUI:

    root = Tk()
    ob = Student(root)
    root.mainloop()
    
    • A Tkinter window (root) is created, and an instance of the Student class (ob) is created with root as its argument.
    • root.mainloop() starts the Tkinter event loop, allowing the GUI to respond to user interactions.
  4. Defining GUI Elements:

    • Labels, entry fields, comboboxes, buttons, and frames are defined within the __init__ method to create the layout of the student management system application.
  5. Managing Student Data:

    • Methods like add_students, fetch_data, clear, get_cursor, update_data, delete_data, and search_data are defined within the Student class to handle different operations related to student data.
    • These methods interact with the SQLite database to perform operations such as adding, updating, deleting, fetching, and searching student records.
  6. SQLite Database:

    • The code connects to an SQLite database named student.db.
    • It defines a table named students to store student records with columns like serial number (sl), name, class, batch, admit date, mobile, parent’s mobile, and payment details for each month.
  7. Error Handling:

    • The code includes error handling mechanisms using try-except blocks and displays error messages using messagebox.showerror in case of any exceptions.
  8. Event Handling:

    • The code binds events like clicking on a table row (<ButtonRelease-1>) to the get_cursor method to handle user interactions.

How to Run Below Code:

To run the provided code, you can follow these steps:

  1. Make sure you have Python installed on your system.
  2. Ensure you have the necessary modules installed. In this case, the code utilizes tkinter, sqlite3, and messagebox from tkinter.
  3. Copy the entire code snippet into a Python file with a .py extension, for example, student_management_system.py.
  4. Open a terminal or command prompt.
  5. Navigate to the directory where your Python file is saved using the cd command.
  6. Run the Python file by executing the command python student.py.

Source Code:

				
					from tkinter import *
from tkinter import ttk
import sqlite3
from tkinter import messagebox

class Student:
    def __init__(self,root):
        self.root = root
        self.root.title("Student Management System")
        self.root.geometry("1350x700+0+0")

        title = Label(self.root,text="Student Management System",bd=6,relief=GROOVE,font=("Algerian",30,'bold'),bg='dark blue',fg='white' )
        title.pack(side=TOP,fill=X)


        self.sl_var = StringVar()
        self.name_var = StringVar()
        self.class_var = StringVar()
        self.batch_var = StringVar()
        self.adate_var = StringVar()
        self.mob_var = StringVar()
        self.pmob_var = StringVar()

        self.jan_var = ""
        self.feb_var = ""
        self.mar_var = ""
        self.apr_var = ""
        self.may_var = ""
        self.jun_var = ""
        self.jul_var = ""
        self.aug_var = ""
        self.sep_var = ""
        self.oct_var = ""
        self.nov_var = ""
        self.dec_var = ""
        

        self.pay_month_var = StringVar()
        self.pay_amount_var = StringVar()

    
        self.search_by = StringVar()
        self.search_txt = StringVar()


        title = Label(self.root,text="Visit: CodeWithCurious.com/projects for more projects",bd=3,relief=GROOVE,font=("Brush Script MT",18),bg='blue',fg='white' )
        title.pack(side=BOTTOM,fill=X)        

        manage_frame = Label(self.root,bd=4,relief=RIDGE,bg='light blue')
        manage_frame.place(x=15,y=80,width=460,height=580)

        m_title=Label(manage_frame,text="Manage Students",bg="light blue",fg="black",font=("times new roman",18,"bold"))
        m_title.grid(row=0,columnspan=2,pady=10)


        lbl_sl=Label(manage_frame,text="Serial No",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_sl.grid(row=1,column=0,pady=10,padx=20,sticky='w')

        txt_sl = Entry(manage_frame,textvariable= self.sl_var, font=('times new roman',14),bd=2,relief=GROOVE)
        txt_sl.grid(row=1,column=1,pady=10,padx=20,sticky='w')


        lbl_name=Label(manage_frame,text="Name",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_name.grid(row=2,column=0,pady=10,padx=20,sticky='w')

        txt_name = Entry(manage_frame,textvariable=self.name_var,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_name.grid(row=2,column=1,pady=10,padx=20,sticky='w')

        lbl_class=Label(manage_frame,text="Class",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_class.grid(row=3,column=0,pady=10,padx=20,sticky='w')

        combo_class = ttk.Combobox(manage_frame,textvariable=self.class_var,font=("times new roman",12,'bold'),state='readonly')
        combo_class['values']=("Class 1","Class 2","Class 3","Class 4","Class 5","Class 6","Class 7","Class 8","Class 9","Class 10")
        combo_class.grid(row=3,column=1,pady=10,padx=20) 

        lbl_batch=Label(manage_frame,text="Batch Name",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_batch.grid(row=4,column=0,pady=10,padx=20,sticky='w')


        txt_batch = Entry(manage_frame,textvariable=self.batch_var,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_batch.grid(row=4,column=1,pady=10,padx=20,sticky='w')

        lbl_adate=Label(manage_frame,text="Payment Date",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_adate.grid(row=5,column=0,pady=10,padx=20,sticky='w')

        txt_adate = Entry(manage_frame,textvariable=self.adate_var,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_adate.grid(row=5,column=1,pady=10,padx=20,sticky='w')


        lbl_mob=Label(manage_frame,text="Mobile",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_mob.grid(row=6,column=0,pady=10,padx=20,sticky='w')

        txt_mob = Entry(manage_frame,textvariable=self.mob_var,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_mob.grid(row=6,column=1,pady=10,padx=20,sticky='w')

        lbl_pmob=Label(manage_frame,text="Parents Mobile",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_pmob.grid(row=7,column=0,pady=10,padx=20,sticky='w')

        txt_pmob = Entry(manage_frame,textvariable=self.pmob_var,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_pmob.grid(row=7,column=1,pady=10,padx=20,sticky='w')


        lbl_pay=Label(manage_frame,text="Pay Amount",bg="light blue",fg="black",font=("times new roman",14,'bold'))
        lbl_pay.grid(row=8,column=0)

        combo_pay = ttk.Combobox(manage_frame,width=14,textvariable=self.pay_month_var,font=("times new roman",12,'bold'),state='readonly')
        combo_pay['values']=("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec")
        combo_pay.grid(row=8,column=1)

        txt_pay = Entry(manage_frame,textvariable=self.pay_amount_var,width=5,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_pay.grid(row=8,column=2)        

        btn_frame = Frame(manage_frame,bd=4,relief=RIDGE,bg='white')
        btn_frame.place(x=10,y=470,width=425)

        addbtn = Button(btn_frame,text="Add",width=10,command=self.add_students).grid(row=0,column=0,padx=10,pady=10)
        updatebtn = Button(btn_frame,text="Update",width=10,command=self.update_data).grid(row=0,column=1,padx=10,pady=10)
        deletebtn = Button(btn_frame,text="Delete",width=10,command=self.delete_data).grid(row=0,column=2,padx=10,pady=10)
        clearbtn = Button(btn_frame,text="Clear",width=10,command=self.clear).grid(row=0,column=3,padx=10,pady=10)
        

        detail_frame = Frame(self.root,bd=4,relief=RIDGE,bg='light blue')
        detail_frame.place(x=500,y=80,width=820,height=580)

        lbl_search = Label(detail_frame,text="Search By",bg="light blue",fg="black",font=("times new roman",16,'bold'))
        lbl_search.grid(row=0,column=0,pady=10,padx=20,sticky='w')

  
        combo_search = ttk.Combobox(detail_frame,width=10,textvariable=self.search_by,font=("times new roman",12,'bold'),state='readonly')
        combo_search['values']=("sl","name","class")
        combo_search.grid(row=0,column=1,pady=10,padx=20)

        txt_search = Entry(detail_frame,width=30,textvariable=self.search_txt,font=('times new roman',14),bd=2,relief=GROOVE)
        txt_search.grid(row=0,column=2,pady=10,padx=20,sticky='w')

        searchbtn = Button(detail_frame,text="Search",width=10,command=self.search_data).grid(row=0,column=3,padx=10,pady=10)
        showallbtn = Button(detail_frame,text="Show All",width=10,command=self.fetch_data).grid(row=0,column=4,padx=10,pady=10)


        table_frame = Frame(detail_frame,bd=2,relief=RIDGE,bg='light blue')
        table_frame.place(x=10,y=80,width=785,height=480)

        scroll_x = Scrollbar(table_frame,orient="horizontal")
        scroll_y = Scrollbar(table_frame,orient="vertical")
        self.student_table = ttk.Treeview(table_frame,columns=("sl","name","class","batch","adate","mob","pmob",
                                                               "jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"),
                                                              xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set) 
        scroll_x.pack(side=BOTTOM,fill=X)
        scroll_y.pack(side=RIGHT,fill=Y)
        scroll_x.config(command=self.student_table.xview)
        scroll_y.config(command=self.student_table.yview)
        self.student_table.heading("sl",text="Sl.No")
        self.student_table.heading("name",text="Name")
        self.student_table.heading("class",text="Class")
        self.student_table.heading("batch",text="Batch")
        self.student_table.heading("adate",text="Admit Date")
        self.student_table.heading("mob",text="Mobile")
        self.student_table.heading("pmob",text="Parents Mobile")

        self.student_table.heading("jan",text="January")
        self.student_table.heading("feb",text="February")
        self.student_table.heading("mar",text="March")
        self.student_table.heading("apr",text="April")
        self.student_table.heading("may",text="May")
        self.student_table.heading("jun",text="June")
        self.student_table.heading("jul",text="July")
        self.student_table.heading("aug",text="August")
        self.student_table.heading("sep",text="September")
        self.student_table.heading("oct",text="October")
        self.student_table.heading("nov",text="November")
        self.student_table.heading("dec",text="December")

        self.student_table['show']='headings'

        self.student_table.column("sl",width=80)
        self.student_table.column("name",width=200)
        self.student_table.column("class",width=140)
        self.student_table.column("batch",width=140)
        self.student_table.column("adate",width=140)
        self.student_table.column("mob",width=140)
        self.student_table.column("pmob",width=140)
        self.student_table.pack(fill=BOTH,expand=1)
        self.student_table.bind("<ButtonRelease-1>",self.get_cursor)
        self.fetch_data()
    def add_students(self):

        if self.sl_var.get()=="" or self.name_var.get()=="" or self.class_var.get()=="":
            messagebox.showerror("Error","All fields are required!")
        else:
            conn=sqlite3.connect("student.db")
            cur=conn.cursor()
            cur.execute("""CREATE TABLE IF NOT EXISTS students(sl integer,name TEXT,class TEXT,batch TEXT,adate TEXT,
                            mob TEXT,pmob TEXT,jan TEXT,feb TEXT,mar TEXT,apr TEXT,may TEXT, jun TEXT,
                            jul TEXT,aug TEXT, sep TEXT,oct TEXT,nov TEXT,dec TEXT)""")

            self.set_data()
            cur.execute("insert into students values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)",(
                                                                        int(self.sl_var.get()),
                                                                        self.name_var.get(),
                                                                        self.class_var.get(),
                                                                        self.batch_var.get(),
                                                                        self.adate_var.get(),
                                                                        self.mob_var.get(),
                                                                        self.pmob_var.get(),self.jan_var,self.feb_var,
                                                                        self.mar_var,self.apr_var,self.may_var,self.jun_var,
                                                                        self.jul_var,self.aug_var,self.sep_var,self.oct_var,
                                                                        self.nov_var,self.dec_var))
                                                                                                                                                             
            conn.commit()
            self.fetch_data()
            self.clear()
            conn.close()
            messagebox.showinfo("Success","Record has been inserted successfully.")
            
    def fetch_data(self):
        conn=sqlite3.connect("student.db")
        cur=conn.cursor()
        cur.execute("select * from students")
        rows = cur.fetchall()
        if len(rows)!=0:
            self.student_table.delete(*self.student_table.get_children())
            for row in rows:
                self.student_table.insert("",END,values=row)
            conn.commit()
        conn.close()

    def clear(self):
        self.sl_var.set("")
        self.name_var.set("")
        self.class_var.set("")
        self.batch_var.set("")
        self.adate_var.set("")
        self.mob_var.set("")
        self.pmob_var.set("")
        self.pay_month_var.set("")
        self.pay_amount_var.set("")
        
    def get_cursor(self,event):
        cursor_row =  self.student_table.focus()
        contents = self.student_table.item(cursor_row)
        row = contents['values']
        self.sl_var.set(row[0])
        self.name_var.set(row[1])
        self.class_var.set(row[2])
        self.batch_var.set(row[3])
        self.adate_var.set(row[4])
        self.mob_var.set(row[5])
        self.pmob_var.set(row[6])

    def update_data(self):
        conn=sqlite3.connect("student.db")
        cur=conn.cursor()
        self.set_data()
        cur.execute("""update students set name=?,class=?,batch=?,adate=?,mob=?,pmob=?,jan=?,
                       feb=?,mar=?,apr=?,may=?,jun=?,jul=?,aug=?,sep=?,oct=?,nov=?,dec=? where sl=?""",(
                                                                        self.name_var.get(),
                                                                        self.class_var.get(),
                                                                        self.batch_var.get(),
                                                                        self.adate_var.get(),
                                                                        self.mob_var.get(),
                                                                        self.pmob_var.get(),self.jan_var,self.feb_var,
                                                                        self.mar_var,self.apr_var,self.may_var,self.jun_var,
                                                                        self.jul_var,self.aug_var,self.sep_var,self.oct_var,
                                                                        self.nov_var,self.dec_var,
                                                                        int(self.sl_var.get())))
                   
        conn.commit()
        self.fetch_data()
        self.clear()
        conn.close()
        messagebox.showinfo("Success","Record has been updated successfully.")
    def delete_data(self):
        conn=sqlite3.connect("student.db")
        cur=conn.cursor()
        cur.execute("delete from students where sl=?",(int(self.sl_var.get()),))
        conn.commit()
        self.fetch_data()
        self.clear()
        conn.close()
        messagebox.showinfo("Success","Record has been deleted successfully.")

    def search_data(self):
        #==================================for sqlite3==================
        conn=sqlite3.connect("student.db")
        cur=conn.cursor()
        cur.execute("select * from students where "+str(self.search_by.get())+" LIKE '%"+str(self.search_txt.get())+"%'")
        rows = cur.fetchall()
        if len(rows)!=0:
            self.student_table.delete(*self.student_table.get_children())
            for row in rows:
                self.student_table.insert("",END,values=row)
            conn.commit()
        else:
            messagebox.showerror("Error","Record doesn't find")
        conn.close()

    def set_data(self):
        if self.pay_month_var.get()=="jan":
            self.jan_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="feb":
            self.feb_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="mar":
            self.mar_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="apr":
            self.apr_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="may":
            self.may_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="jun":
            self.jun_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="jul":
            self.jul_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="aug":
            self.aug_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="sep":
            self.sep_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="oct":
            self.oct_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="nov":
            self.nov_var = self.pay_amount_var.get()
        elif self.pay_month_var.get()=="dec":
            self.dec_var = self.pay_amount_var.get()
        
root = Tk()
ob = Student(root)
root.mainloop()
				
			

Output:

More Projects:

More Python Projects
Get Huge Discounts

All Coding Handwritten Notes

Browse Handwritten Notes