├── college_images ├── 3.jpg ├── 5th.jpg ├── 6th.jpg ├── 7th.jpg ├── logo.jpg ├── mits.jpg ├── university.png └── mits gwalior.png ├── Student Management System.png ├── sms.sql ├── LICENSE ├── README.md └── student.py /college_images/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/3.jpg -------------------------------------------------------------------------------- /college_images/5th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/5th.jpg -------------------------------------------------------------------------------- /college_images/6th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/6th.jpg -------------------------------------------------------------------------------- /college_images/7th.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/7th.jpg -------------------------------------------------------------------------------- /college_images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/logo.jpg -------------------------------------------------------------------------------- /college_images/mits.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/mits.jpg -------------------------------------------------------------------------------- /Student Management System.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/Student Management System.png -------------------------------------------------------------------------------- /college_images/university.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/university.png -------------------------------------------------------------------------------- /college_images/mits gwalior.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alok-2002/Advanced-Student-Management-System/HEAD/college_images/mits gwalior.png -------------------------------------------------------------------------------- /sms.sql: -------------------------------------------------------------------------------- 1 | -- Create the database schema 2 | CREATE DATABASE IF NOT EXISTS student_management_system; 3 | 4 | -- Use the created database 5 | USE student_management_system; 6 | 7 | -- Create the table to store student information 8 | CREATE TABLE IF NOT EXISTS student ( 9 | Enrollment VARCHAR(20) PRIMARY KEY, 10 | Name VARCHAR(100), 11 | Course VARCHAR(50), 12 | Department VARCHAR(100), 13 | Year VARCHAR(20), 14 | Semester VARCHAR(20), 15 | Section VARCHAR(10), 16 | Gender VARCHAR(10), 17 | Dob DATE, 18 | Phone VARCHAR(15), 19 | Email VARCHAR(100), 20 | Address VARCHAR(255) 21 | ); 22 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Alok Sharma 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Student Management System with MySQL Database 2 | 3 | The Student Management System (SMS) is a GUI application created with Python and tkinter. It is designed to manage student data for a school or university. This version of the system utilizes a MySQL database to store and retrieve student information, such as names, addresses, contact information, and academic records. 4 | 5 | ![Student Management System](https://github.com/Alok-2002/Advanced-Student-Management-System/assets/93814546/05f766d7-f2d2-4c2c-8ba3-56cd26acd642) 6 | 7 | 8 | ## Features 9 | 10 | - Add new students to the system 11 | - Edit existing student information 12 | - Delete students from the system 13 | - View a list of all students in the system 14 | - Search for a specific student by name or ID 15 | - Export student data to a CSV file 16 | 17 | ## Installation 18 | 19 | 1. Clone this repository to your local machine. 20 | 2. Install the required dependencies using 21 | ```bash 22 | pip install pip install pillow mysql-connector-python 23 | ``` 24 | 4. Create a MySQL database and import the `sms.sql` file to create the necessary tables. 25 | 5. Modify the `config.ini` file to include your MySQL database credentials. 26 | 6. Run the `student.py` file to launch the application. 27 | 28 | ## Usage 29 | 30 | Upon launching the application, you will be presented with a GUI window that displays a list of all students in the system. From there, you can perform various actions on the student data using the buttons and fields provided. 31 | 32 | ### Adding a new student 33 | 34 | To add a new student, click the "Add Student" button and fill out the required fields in the form that appears. Once you have entered all the necessary information, click "Save" to add the new student to the system. 35 | 36 | ### Editing a student 37 | 38 | To edit an existing student's information, select the student from the list and click the "Edit Student" button. This will bring up the same form used for adding a new student, but with the fields pre-filled with the student's current information. Make any necessary changes and click "Save" to update the student's data. 39 | 40 | ### Deleting a student 41 | 42 | To delete a student from the system, select the student from the list and click the "Delete Student" button. You will be prompted to confirm the deletion before the student is removed from the system. 43 | 44 | ### Searching for a student 45 | 46 | To search for a specific student, enter the student's name or ID in the search field at the top of the window and click "Search". The list of students will be filtered to show only those that match your search criteria. 47 | 48 | ### Exporting student data 49 | 50 | To export the student data to a CSV file, click the "Export to CSV" button. The file will be saved in the same directory as the application. 51 | 52 | ## Contributing 53 | 54 | If you find a bug or would like to suggest a new feature, please open an issue or submit a pull request on GitHub. Contributions are always welcome! 55 | -------------------------------------------------------------------------------- /student.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import ttk 3 | from PIL import Image,ImageTk 4 | import mysql.connector 5 | from tkinter import messagebox 6 | 7 | class Student: 8 | def __init__(self,root): 9 | self.root=root 10 | self.root.geometry("1530x790+0+0") 11 | self.root.title("STUDENT REGISTRATION SYSTEM") 12 | 13 | #variables 14 | self.var_enrollment=StringVar() 15 | self.var_name=StringVar() 16 | self.var_course=StringVar() 17 | self.var_department=StringVar() 18 | self.var_year=StringVar() 19 | self.var_semester=StringVar() 20 | self.var_section=StringVar() 21 | self.var_gender=StringVar() 22 | self.var_dob=StringVar() 23 | self.var_phone=StringVar() 24 | self.var_email=StringVar() 25 | self.var_address=StringVar() 26 | 27 | #1st image 28 | img=Image.open(r'./college_images/mits.jpg') 29 | img=img.resize((1550,170),Image.ANTIALIAS) 30 | self.photoimg=ImageTk.PhotoImage(img) 31 | 32 | self.button1=Button(self.root,image=self.photoimg,cursor="hand2") 33 | self.button1.place(x=0,y=0,width=1550,height=170) 34 | 35 | #background image 36 | img_4=Image.open(r'./college_images/university.png') 37 | img_4=img_4.resize((1530,710),Image.ANTIALIAS) 38 | self.photoimg_4=ImageTk.PhotoImage(img_4) 39 | 40 | bg_label=Label(self.root,image=self.photoimg_4,bd=2,relief=RIDGE) 41 | bg_label.place(x=0,y=160,width=1530,height=650) 42 | 43 | label_title=Label(bg_label,text="STUDENT REGISTRATION SYSTEM",font=("Comic Sans MS",37,"bold"),fg="blue",bg="white") 44 | label_title.place(x=0,y=0,width=1530,height=50) 45 | 46 | #manage frames 47 | manage_frame=Frame(bg_label,bd=2,relief=RIDGE,bg="white") 48 | manage_frame.place(x=15,y=55,width=1500,height=560) 49 | 50 | #left data frame 51 | left_frame=LabelFrame(manage_frame,bd=4,relief=RIDGE,padx=2,text="Student Information",font=("Comic Sans MS",12,"bold"),fg="red",bg="white") 52 | left_frame.place(x=10,y=10,width=660,height=540) 53 | 54 | img_5=Image.open(r'./college_images/3.jpg') 55 | img_5=img_5.resize((650,120),Image.ANTIALIAS) 56 | self.photoimg_5=ImageTk.PhotoImage(img_5) 57 | 58 | my_labl=Label(left_frame,image=self.photoimg_5,bd=2,relief=RIDGE) 59 | my_labl.place(x=0,y=0,width=650,height=120) 60 | 61 | #current course 62 | student_info_frame=LabelFrame(manage_frame,bd=4,relief=RIDGE,padx=2,text="Current Course Information",font=("Comic Sans MS",12,"bold"),fg="red",bg="white") 63 | student_info_frame.place(x=0,y=120,width=667,height=115) 64 | 65 | course_label=Label(student_info_frame,text="Course",font=("Comic Sans MS",12,"bold"),bg="white") 66 | course_label.grid(row=0,column=0,padx=2,pady=10,sticky=W) 67 | 68 | course_combo=ttk.Combobox(student_info_frame,textvariable=self.var_course,font=("Arial",12,"bold"),width=17,state="readonly") 69 | course_combo["value"]=("Select Courses","B.E/B.Tech","Ph.D","MBA","MCA","M.E","M.Tech") 70 | course_combo.current(0) 71 | course_combo.grid(row=0,column=1,padx=2,pady=10,sticky=W) 72 | 73 | #department drop box 74 | department_label=Label(student_info_frame,text="Department",font=("Comic Sans MS",12,"bold"),bg="white") 75 | department_label.grid(row=0,column=2,padx=2,sticky=W) 76 | 77 | department_combo=ttk.Combobox(student_info_frame,textvariable=self.var_department,font=("Arial",12,"bold"),width=17,state="readonly") 78 | department_combo["value"]=("Select Department","Computer Science And Engineering","Computer Science And Design","Information Technology","Artificial Intelligence And Machine Learning","Artificial Intelligence And Data Science","Artificial Intelligence And Robotics","Electrical Engineering","Internet Of Things Offered By Electrical Engineering Department","Internet Of Things Offered By Information Technology","Mathematics And Computing","Autombile Engineering","Electronics And TeleCommunication","Chemical Engineering","Architecture","Electronics Engineering","Civil Engineering Department","Mechanical Engineering") 79 | department_combo.current(0) 80 | department_combo.grid(row=0,column=3,padx=2,pady=10,sticky=W) 81 | 82 | #year 83 | current_year=Label(student_info_frame,text="Year:",font=("Comic Sans MS",12,"bold"),bg="white") 84 | current_year.grid(row=1,column=0,padx=2,sticky=W) 85 | 86 | current_year_combo=ttk.Combobox(student_info_frame,textvariable=self.var_year,font=("Arial",12,"bold"),width=17,state="readonly") 87 | current_year_combo["value"]=("Select Your Current Year","1st Year","2nd Year","3rd Year","4th Year") 88 | current_year_combo.current(0) 89 | current_year_combo.grid(row=1,column=1,padx=2,pady=10,sticky=W) 90 | 91 | #current semester 92 | current_semester=Label(student_info_frame,text="Semester:",font=("Comic Sans MS",12,"bold"),bg="white") 93 | current_semester.grid(row=1,column=2,padx=2,pady=10,sticky=W) 94 | 95 | current_semester_combo=ttk.Combobox(student_info_frame,textvariable=self.var_semester,font=("Arial",12,"bold"),width=17,state="readonly") 96 | current_semester_combo["value"]=("Select Your Current Semester","1st Semester","2nd Semester","3rd Semester","4th Semester","5th Semester","6th Semester","7th Semester","8th Semester") 97 | current_semester_combo.current(0) 98 | current_semester_combo.grid(row=1,column=3,padx=2,pady=10,sticky=W) 99 | 100 | #student class information 101 | student_class=LabelFrame(left_frame,bd=4,relief=RIDGE,padx=2,text="Student Class Information",font=("Comic Sans MS",12,"bold"),fg="red",bg="white") 102 | student_class.place(x=0,y=195,width=650,height=235) 103 | 104 | #student name 105 | student_name=Label(student_class,text="Student Name: ",font=("Comic Sans MS",12,"bold"),bg="white") 106 | student_name.grid(row=0,column=0,padx=2,pady=7,sticky=W) 107 | 108 | name_entry=ttk.Entry(student_class,textvariable=self.var_name,font=("Comic Sans MS",12,"bold"),width=15) 109 | name_entry.grid(row=0,column=1,sticky=W,padx=2,pady=7) 110 | 111 | #student id 112 | student_id=Label(student_class,text="Enrollment",font=("Comic Sans MS",12,"bold"),bg="white") 113 | student_id.grid(row=0,column=2,padx=2,pady=7,sticky=W) 114 | 115 | id_entry=ttk.Entry(student_class,textvariable=self.var_enrollment,font=("Comic Sans MS",12,"bold"),width=15) 116 | id_entry.grid(row=0,column=3,sticky=W,padx=2,pady=7) 117 | 118 | #sections 119 | class_section=Label(student_class,text="Section: ",font=("Comic Sans MS",12,"bold"),bg="white") 120 | class_section.grid(row=1,column=0,padx=2,pady=7,sticky=W) 121 | 122 | section_entry=ttk.Combobox(student_class,textvariable=self.var_section,state="readonly",font=("Arial",10,"bold"),width=18) 123 | section_entry["values"]=("Select Your Branch Section","A","B","C") 124 | section_entry.current(0) 125 | section_entry.grid(row=1,column=1,sticky=W,padx=2,pady=7) 126 | 127 | #gender 128 | student_gender=Label(student_class,text="Gender:",font=("Comic Sans MS",10,"bold"),bg="white") 129 | student_gender.grid(row=1,column=2,padx=2,pady=7,sticky=W) 130 | 131 | gender_combo=ttk.Combobox(student_class,textvariable=self.var_gender,state="readonly",font=("Arial",10,"bold"),width=19) 132 | gender_combo["values"]=("Select Your Gender","Male","Female") 133 | gender_combo.current(0) 134 | gender_combo.grid(row=1,column=3,sticky=W,padx=2,pady=7) 135 | 136 | #dob 137 | student_dob=Label(student_class,text="DOB:",font=("Comic Sans MS",12,"bold"),bg="white") 138 | student_dob.grid(row=2,column=0,padx=2,pady=7,sticky=W) 139 | 140 | dob_entry=ttk.Entry(student_class,textvariable=self.var_dob,font=("Arial",12,"bold"),width=15) 141 | dob_entry.grid(row=2,column=1,sticky=W,padx=2,pady=7) 142 | 143 | #mobilenumber 144 | student_mobile=Label(student_class,text="Phone",font=("Comic Sans MS",12,"bold"),bg="white") 145 | student_mobile.grid(row=2,column=2,padx=2,pady=7,sticky=W) 146 | 147 | num_entry=ttk.Entry(student_class,textvariable=self.var_phone,font=("Arial",12,"bold"),width=16) 148 | num_entry.grid(row=2,column=3,sticky=W,padx=2,pady=7) 149 | 150 | #mail 151 | student_email=Label(student_class,text="Email I'D:",font=("Comic Sans MS",12,"bold"),bg="white") 152 | student_email.grid(row=3,column=0,padx=2,pady=7,sticky=W) 153 | 154 | email_entry=ttk.Entry(student_class,textvariable=self.var_email,font=("calbri",12,"bold"),width=15) 155 | email_entry.grid(row=3,column=1,sticky=W,padx=2,pady=7) 156 | 157 | #address 158 | student_address=Label(student_class,text="Address:",font=("Comic Sans MS",12,"bold"),bg="white") 159 | student_address.grid(row=3,column=2,padx=2,pady=7,sticky=W) 160 | 161 | address_entry=ttk.Entry(student_class,textvariable=self.var_address,font=("Comic Sans MS",12,"bold"),width=15) 162 | address_entry.grid(row=3,column=3,sticky=W,padx=2,pady=7) 163 | 164 | #button 165 | button_frame=Frame(left_frame,bd=2,relief=RIDGE,bg="white") 166 | button_frame.place(x=0,y=435,width=650,height=45) 167 | 168 | button_add=Button(button_frame,text="Save",command=self.add_data,font=("arial",14,"bold"),width=13,bg="blue",fg="white") 169 | button_add.grid(row=0,column=0,padx=1) 170 | 171 | button_update=Button(button_frame,text="Update",command=self.update_data,font=("arial",14,"bold"),width=13,bg="blue",fg="white") 172 | button_update.grid(row=0,column=1,padx=1) 173 | 174 | button_del=Button(button_frame,text="Delete",command=self.delete_data,font=("arial",14,"bold"),width=13,bg="blue",fg="white") 175 | button_del.grid(row=0,column=2,padx=1) 176 | 177 | button_reset=Button(button_frame,text="Reset",command=self.reset_data,font=("arial",14,"bold"),width=12,bg="blue",fg="white") 178 | button_reset.grid(row=0,column=3,padx=1) 179 | 180 | 181 | #right frame 182 | right_frame=LabelFrame(manage_frame,bd=4,relief=RIDGE,padx=2,text="Student Details",font=("Comic Sans MS",12,"bold"),fg="red",bg="white") 183 | right_frame.place(x=680,y=10,width=810,height=540) 184 | 185 | #img 1 186 | img_7=Image.open(r'./college_images/5th.jpg') 187 | img_7=img_7.resize((798,200),Image.ANTIALIAS) 188 | self.photoimg_7=ImageTk.PhotoImage(img_7) 189 | 190 | right_img=Label(right_frame,image=self.photoimg_7,bd=2,relief=RIDGE) 191 | right_img.place(x=0,y=0,width=798,height=200) 192 | 193 | #search frame 194 | search_frame=LabelFrame(right_frame,bd=4,relief=RIDGE,padx=2,text="Search Student Information",font=("Comic Sans MS",12,"bold"),fg="red",bg="white") 195 | search_frame.place(x=0,y=200,width=798,height=70) 196 | 197 | search_label=Label(search_frame,font=("arial",14,"bold"),text="Search By: ",width=12,bg="grey",fg="Black") 198 | search_label.grid(row=0,column=0,padx=5,sticky=W) 199 | 200 | #Search 201 | self.var_combo_search=StringVar() 202 | 203 | search_combo=ttk.Combobox(search_frame,textvariable=self.var_combo_search,state="readonly",font=("Arial",10,"bold"),width=19) 204 | search_combo["values"]=("Select Option","Enrollment","Phone","Name") 205 | search_combo.current(0) 206 | search_combo.grid(row=0,column=1,sticky=W,padx=5) 207 | 208 | self.var_search=StringVar() 209 | 210 | search_entry=ttk.Entry(search_frame,textvariable=self.var_search,font=("Comic Sans MS",12,"bold"),width=15) 211 | search_entry.grid(row=0,column=2,sticky=W,padx=5) 212 | 213 | button_search=Button(search_frame,text="Search",command=self.search_data,font=("arial",14,"bold"),width=11,bg="blue",fg="white") 214 | button_search.grid(row=0,column=3,padx=5) 215 | 216 | button_ShowAll=Button(search_frame,command=self.fetch_data,text="Show All",font=("arial",14,"bold"),width=10,bg="blue",fg="white") 217 | button_ShowAll.grid(row=0,column=4,padx=5) 218 | 219 | #=======Student Table And Scroll Bar======== 220 | table_frame=Frame(right_frame,bd=4,relief=RIDGE) 221 | table_frame.place(x=0,y=272,width=797,height=240) 222 | 223 | scroll_x=ttk.Scrollbar(table_frame,orient=HORIZONTAL) 224 | scroll_y=ttk.Scrollbar(table_frame,orient=VERTICAL) 225 | self.student_table=ttk.Treeview(table_frame,columns=("Enrollment","Name","Course","Department","Year","Semester","Section","Gender","Dob","Phone","Email","Address"),xscrollcommand=scroll_x.set,yscrollcommand=scroll_y.set) 226 | scroll_x.pack(side=BOTTOM,fill=X) 227 | scroll_y.pack(side=RIGHT,fill=Y) 228 | 229 | scroll_x.config(command=self.student_table.xview) 230 | scroll_y.config(command=self.student_table.yview) 231 | 232 | self.student_table.heading("Enrollment",text="Enrollment") 233 | self.student_table.heading("Name",text="Name") 234 | self.student_table.heading("Course",text="Course") 235 | self.student_table.heading("Department",text="Department") 236 | self.student_table.heading("Year",text="Year") 237 | self.student_table.heading("Semester",text="Semester") 238 | self.student_table.heading("Section",text="Section") 239 | self.student_table.heading("Gender",text="Gender") 240 | self.student_table.heading("Dob",text="DOB") 241 | self.student_table.heading("Phone",text="Phone") 242 | self.student_table.heading("Email",text="Email") 243 | self.student_table.heading("Address",text="Address") 244 | 245 | self.student_table["show"]="headings" 246 | 247 | self.student_table.column("Enrollment",width=100) 248 | self.student_table.column("Name",width=100) 249 | self.student_table.column("Course",width=100) 250 | self.student_table.column("Department",width=100) 251 | self.student_table.column("Year",width=100) 252 | self.student_table.column("Semester",width=100) 253 | self.student_table.column("Section",width=100) 254 | self.student_table.column("Gender",width=100) 255 | self.student_table.column("Dob",width=100) 256 | self.student_table.column("Phone",width=100) 257 | self.student_table.column("Email",width=100) 258 | self.student_table.column("Address",width=100) 259 | 260 | self.student_table.pack(fill=BOTH,expand=1) 261 | self.student_table.bind("",self.get_cursor) 262 | 263 | self.fetch_data() 264 | 265 | def add_data(self): 266 | if (self.var_enrollment.get()=="" or self.var_name.get()=="" or self.var_course.get()==""): 267 | messagebox.showerror("Error","All Fields Are Required") 268 | else: 269 | try: 270 | conn=mysql.connector.connect(host="localhost",username="root",password="2030",database="student_management_system") 271 | my_cursur=conn.cursor() 272 | my_cursur.execute("insert into student values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",(self.var_enrollment.get(), 273 | self.var_name.get(), 274 | self.var_course.get(), 275 | self.var_department.get(), 276 | self.var_year.get(), 277 | self.var_semester.get(), 278 | self.var_section.get(), 279 | self.var_gender.get(), 280 | self.var_dob.get(), 281 | self.var_phone.get(), 282 | self.var_email.get(), 283 | self.var_address.get() 284 | )) 285 | conn.commit() 286 | self.fetch_data() 287 | conn.close() 288 | messagebox.showinfo("Registration Successfull","Student Has Been Successfully Registered...",parent=self.root) 289 | except Exception as es: 290 | messagebox.showerror("Error",f"Due To:{str(es)}",parent=self.root) 291 | 292 | def fetch_data(self): 293 | conn=mysql.connector.connect(host="localhost",username="root",password="2030",database="student_management_system") 294 | my_cursur=conn.cursor() 295 | my_cursur.execute("select * from student order by Enrollment") 296 | data=my_cursur.fetchall() 297 | if len(data)!=0: 298 | self.student_table.delete(*self.student_table.get_children()) 299 | for i in data: 300 | self.student_table.insert("", END,values=i) 301 | conn.commit() 302 | conn.close() 303 | 304 | #get cursor 305 | def get_cursor(self,event=""): 306 | cursor_row=self.student_table.focus() 307 | content=self.student_table.item(cursor_row) 308 | data=content["values"] 309 | 310 | self.var_enrollment.set(data[0]) 311 | self.var_name.set(data[1]) 312 | self.var_course.set(data[2]) 313 | self.var_department.set(data[3]) 314 | self.var_year.set(data[4]) 315 | self.var_semester.set(data[5]) 316 | self.var_section.set(data[6]) 317 | self.var_gender.set(data[7]) 318 | self.var_dob.set(data[8]) 319 | self.var_phone.set(data[9]) 320 | self.var_email.set(data[10]) 321 | self.var_address.set(data[11]) 322 | 323 | #update in database 324 | def update_data(self): 325 | if (self.var_enrollment.get()=="" or self.var_name.get()=="" or self.var_course.get()==""): 326 | messagebox.showerror("Error","All Fields Are Required") 327 | else: 328 | try: 329 | update=messagebox.askyesno("Update","Are You Sure To Update This Student Information ?",parent=self.root) 330 | if update>0: 331 | conn=mysql.connector.connect(host="localhost",username="root",password="2030",database="student_management_system") 332 | my_cursur=conn.cursor() 333 | my_cursur.execute("update student set Name=%s,Course=%s,Department=%s,Year=%s,Semester=%s,Section=%s,Gender=%s,DOB=%s,Phone=%s,Email=%s,Address=%s where Enrollment=%s",( self.var_name.get(), 334 | self.var_course.get(), 335 | self.var_department.get(), 336 | self.var_year.get(), 337 | self.var_semester.get(), 338 | self.var_section.get(), 339 | self.var_gender.get(), 340 | self.var_dob.get(), 341 | self.var_phone.get(), 342 | self.var_email.get(), 343 | self.var_address.get(), 344 | self.var_enrollment.get() 345 | )) 346 | else: 347 | if not update: 348 | return 349 | conn.commit() 350 | self.fetch_data() 351 | conn.close() 352 | 353 | messagebox.showinfo("Succesfull","Student Information Updated Successfull.....",parent=self.root) 354 | except Exception as es: 355 | messagebox.showerror("Error",f"Due To:{str(es)}",parent=self.root) 356 | 357 | #Delete Button 358 | def delete_data(self): 359 | if self.var_enrollment.get()=="": 360 | messagebox.showerror("Error","All Fields Are Required") 361 | else: 362 | try: 363 | Delete=messagebox.askyesno("Delete","Are You Sure Want To Delete This Student ?") 364 | if Delete > 0 : 365 | conn=mysql.connector.connect(host="localhost",username="root",password="2030",database="student_management_system") 366 | my_cursur=conn.cursor() 367 | sql="delete from student where Enrollment=%s" 368 | value=(self.var_enrollment.get(),) 369 | my_cursur.execute(sql,value) 370 | else: 371 | if not Delete: 372 | return 373 | conn.commit() 374 | self.fetch_data() 375 | conn.close() 376 | messagebox.showinfo("Delete","Your Studen Information Has Been Deleted...",parent=self.root) 377 | except Exception as es: 378 | messagebox.showerror("Error",f"Due To:{str(es)}",parent=self.root) 379 | 380 | #Reset 381 | def reset_data(self): 382 | self.var_enrollment.set("") 383 | self.var_name.set("") 384 | self.var_course.set("Select Course") 385 | self.var_department.set("Select Department") 386 | self.var_year.set("Select Your Current Year") 387 | self.var_semester.set("Select Your Current Semester") 388 | self.var_section.set("Select Your Branch Section") 389 | self.var_gender.set("Select Your Gender") 390 | self.var_dob.set("") 391 | self.var_phone.set("") 392 | self.var_email.set("") 393 | self.var_address.set("") 394 | 395 | #search 396 | def search_data(self): 397 | if self.var_combo_search.get()=="" or self.var_search.get()=="": 398 | messagebox.showerror("Error","Please Select Option") 399 | else: 400 | try: 401 | conn=mysql.connector.connect(host="localhost",username="root",password="2030",database="student_management_system") 402 | my_cursur=conn.cursor() 403 | my_cursur.execute("Select * From Student where " +str(self.var_combo_search.get())+" LIKE '%"+str(self.var_search.get())+"%'") 404 | data=my_cursur.fetchall() 405 | if len(data)!=0: 406 | self.student_table.delete(*self.student_table.get_children()) 407 | for i in data: 408 | self.student_table.insert("",END,values=i) 409 | conn.commit() 410 | conn.close() 411 | except Exception as es: 412 | messagebox.showerror("Error",f"Due To:{str(es)}",parent=self.root) 413 | 414 | #main function 415 | if __name__=="__main__": 416 | root=Tk() 417 | obj=Student(root) 418 | root.mainloop() --------------------------------------------------------------------------------