0% found this document useful (0 votes)
163 views9 pages

Student Management System in Python

1. The document defines a student management system using Tkinter and SQLite that allows users to add, remove, update and view student records from a database table. 2. It connects to a SQLite database called "StudentManagement.db", creates a student table if needed, and defines functions for resetting, adding, removing, viewing and displaying student records. 3. The GUI is created with frames to hold labels, entries, buttons and a tree view to display records from the database table. Functions link the GUI elements to the database operations.

Uploaded by

Yash
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
163 views9 pages

Student Management System in Python

1. The document defines a student management system using Tkinter and SQLite that allows users to add, remove, update and view student records from a database table. 2. It connects to a SQLite database called "StudentManagement.db", creates a student table if needed, and defines functions for resetting, adding, removing, viewing and displaying student records. 3. The GUI is created with frames to hold labels, entries, buttons and a tree view to display records from the database table. Functions link the GUI elements to the database operations.

Uploaded by

Yash
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
  • Imports and Database Setup
  • Functions for Record Handling
  • Error Handling and Record Deletion
  • Viewing Records
  • GUI Window Initialization
  • GUI Components Setup
  • Adding Buttons and Tree View
  • Finalizing GUI Components
  • Finalizing the GUI

import datetime

from tkinter import *


import [Link] as mb
from tkinter import ttk
from tkcalendar import DateEntry # pip install
tkcalendar
import sqlite3

# Creating the universal font variables


headlabelfont = ("Noto Sans CJK TC", 15, 'bold')
labelfont = ('Garamond', 14)
entryfont = ('Garamond', 12)

# Connecting to the Database where all information will


be stored
connector = [Link]('[Link]')
cursor = [Link]()

[Link](
"CREATE TABLE IF NOT EXISTS STUDENT_MANAGEMENT
(STUDENT_ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
NAME TEXT, EMAIL TEXT, PHONE_NO TEXT, GENDER TEXT, DOB
TEXT, STREAM TEXT)"
)

# Creating the functions


def reset_fields():
global name_strvar, email_strvar, contact_strvar,
gender_strvar, dob, stream_strvar

for i in ['name_strvar', 'email_strvar',


'contact_strvar', 'gender_strvar', 'stream_strvar']:
exec(f"{i}.set('')")
dob.set_date([Link]().date())

def reset_form():
global tree
[Link](*tree.get_children())

reset_fields()

def display_records():
[Link](*tree.get_children())

curr = [Link]('SELECT * FROM


STUDENT_MANAGEMENT')
data = [Link]()

for records in data:


[Link]('', END, values=records)

def add_record():
global name_strvar, email_strvar, contact_strvar,
gender_strvar, dob, stream_strvar

name = name_strvar.get()
email = email_strvar.get()
contact = contact_strvar.get()
gender = gender_strvar.get()
DOB = dob.get_date()
stream = stream_strvar.get()
if not name or not email or not contact or not
gender or not DOB or not stream:
[Link]('Error!', "Please fill all the
missing fields!!")
else:
try:
[Link](
'INSERT INTO STUDENT_MANAGEMENT (NAME,
EMAIL, PHONE_NO, GENDER, DOB, STREAM) VALUES
(?,?,?,?,?,?)', (name, email, contact, gender, DOB,
stream)
)
[Link]()
[Link]('Record added', f"Record of
{name} was successfully added")
reset_fields()
display_records()
except:
[Link]('Wrong type', 'The type of the
values entered is not accurate. Pls note that the
contact field can only contain numbers')

def remove_record():
if not [Link]():
[Link]('Error!', 'Please select an item
from the database')
else:
current_item = [Link]()
values = [Link](current_item)
selection = values["values"]
[Link](current_item)

[Link]('DELETE FROM
STUDENT_MANAGEMENT WHERE STUDENT_ID=%d' % selection[0])
[Link]()

[Link]('Done', 'The record you wanted


deleted was successfully deleted.')

display_records()

def view_record():
global name_strvar, email_strvar, contact_strvar,
gender_strvar, dob, stream_strvar

current_item = [Link]()
values = [Link](current_item)
selection = values["values"]

date = [Link](int(selection[5][:4]),
int(selection[5][5:7]), int(selection[5][8:]))

name_strvar.set(selection[1]);
email_strvar.set(selection[2])
contact_strvar.set(selection[3]);
gender_strvar.set(selection[4])
dob.set_date(date); stream_strvar.set(selection[6])

# Initializing the GUI window


main = Tk()
[Link]('DataFlair Student Management System')
[Link]('1000x600')
[Link](0, 0)

# Creating the background and foreground color variables


lf_bg = 'MediumSpringGreen' # bg color for the
left_frame
cf_bg = 'PaleGreen' # bg color for the center_frame

# Creating the StringVar or IntVar variables


name_strvar = StringVar()
email_strvar = StringVar()
contact_strvar = StringVar()
gender_strvar = StringVar()
stream_strvar = StringVar()

# Placing the components in the main window


Label(main, text="STUDENT MANAGEMENT SYSTEM",
font=headlabelfont, bg='SpringGreen').pack(side=TOP,
fill=X)

left_frame = Frame(main, bg=lf_bg)


left_frame.place(x=0, y=30, relheight=1, relwidth=0.2)

center_frame = Frame(main, bg=cf_bg)


center_frame.place(relx=0.2, y=30, relheight=1,
relwidth=0.2)

right_frame = Frame(main, bg="Gray35")


right_frame.place(relx=0.4, y=30, relheight=1,
relwidth=0.6)
# Placing components in the left frame
Label(left_frame, text="Name", font=labelfont,
bg=lf_bg).place(relx=0.375, rely=0.05)
Label(left_frame, text="Contact Number", font=labelfont,
bg=lf_bg).place(relx=0.175, rely=0.18)
Label(left_frame, text="Email Address", font=labelfont,
bg=lf_bg).place(relx=0.2, rely=0.31)
Label(left_frame, text="Gender", font=labelfont,
bg=lf_bg).place(relx=0.3, rely=0.44)
Label(left_frame, text="Date of Birth (DOB)",
font=labelfont, bg=lf_bg).place(relx=0.1, rely=0.57)
Label(left_frame, text="Stream", font=labelfont,
bg=lf_bg).place(relx=0.3, rely=0.7)

Entry(left_frame, width=19, textvariable=name_strvar,


font=entryfont).place(x=20, rely=0.1)
Entry(left_frame, width=19, textvariable=contact_strvar,
font=entryfont).place(x=20, rely=0.23)
Entry(left_frame, width=19, textvariable=email_strvar,
font=entryfont).place(x=20, rely=0.36)
Entry(left_frame, width=19, textvariable=stream_strvar,
font=entryfont).place(x=20, rely=0.75)

OptionMenu(left_frame, gender_strvar, 'Male',


"Female").place(x=45, rely=0.49, relwidth=0.5)

dob = DateEntry(left_frame, font=("Arial", 12),


width=15)
[Link](x=20, rely=0.62)
Button(left_frame, text='Submit and Add Record',
font=labelfont, command=add_record,
width=18).place(relx=0.025, rely=0.85)

# Placing components in the center frame


Button(center_frame, text='Delete Record',
font=labelfont, command=remove_record,
width=15).place(relx=0.1, rely=0.25)
Button(center_frame, text='View Record', font=labelfont,
command=view_record, width=15).place(relx=0.1,
rely=0.35)
Button(center_frame, text='Reset Fields',
font=labelfont, command=reset_fields,
width=15).place(relx=0.1, rely=0.45)
Button(center_frame, text='Delete database',
font=labelfont, command=reset_form,
width=15).place(relx=0.1, rely=0.55)

# Placing components in the right frame


Label(right_frame, text='Students Records',
font=headlabelfont, bg='DarkGreen',
fg='LightCyan').pack(side=TOP, fill=X)

tree = [Link](right_frame, height=100,


selectmode=BROWSE,
columns=('Student ID', "Name",
"Email Address", "Contact Number", "Gender", "Date of
Birth", "Stream"))

X_scroller = Scrollbar(tree, orient=HORIZONTAL,


command=[Link])
Y_scroller = Scrollbar(tree, orient=VERTICAL,
command=[Link])

X_scroller.pack(side=BOTTOM, fill=X)
Y_scroller.pack(side=RIGHT, fill=Y)

[Link](yscrollcommand=Y_scroller.set,
xscrollcommand=X_scroller.set)

[Link]('Student ID', text='ID', anchor=CENTER)


[Link]('Name', text='Name', anchor=CENTER)
[Link]('Email Address', text='Email ID',
anchor=CENTER)
[Link]('Contact Number', text='Phone No',
anchor=CENTER)
[Link]('Gender', text='Gender', anchor=CENTER)
[Link]('Date of Birth', text='DOB', anchor=CENTER)
[Link]('Stream', text='Stream', anchor=CENTER)

[Link]('#0', width=0, stretch=NO)


[Link]('#1', width=40, stretch=NO)
[Link]('#2', width=140, stretch=NO)
[Link]('#3', width=200, stretch=NO)
[Link]('#4', width=80, stretch=NO)
[Link]('#5', width=80, stretch=NO)
[Link]('#6', width=80, stretch=NO)
[Link]('#7', width=150, stretch=NO)

[Link](y=30, relwidth=1, relheight=0.9, relx=0)

display_records()
# Finalizing the GUI window
[Link]()
[Link]()

import datetime 
from tkinter import * 
import tkinter.messagebox as mb 
from tkinter import ttk 
from tkcalendar import Date
exec(f"{i}.set('')") 
    dob.set_date(datetime.datetime.now().date()) 
 
def reset_form(): 
    global tree 
    tre
if not name or not email or not contact or not 
gender or not DOB or not stream: 
        mb.showerror('Error!', "Pleas
tree.delete(current_item) 
 
        connector.execute('DELETE FROM 
STUDENT_MANAGEMENT WHERE STUDENT_ID=%d' % sele
main = Tk() 
main.title('DataFlair Student Management System') 
main.geometry('1000x600') 
main.resizable(0, 0) 
 
# Creating
# Placing components in the left frame 
Label(left_frame, text="Name", font=labelfont, 
bg=lf_bg).place(relx=0.375, rely=0.
Button(left_frame, text='Submit and Add Record', 
font=labelfont, command=add_record, 
width=18).place(relx=0.025, rely=0.85)
Y_scroller = Scrollbar(tree, orient=VERTICAL, 
command=tree.yview) 
 
X_scroller.pack(side=BOTTOM, fill=X) 
Y_scroller.pack(s
# Finalizing the GUI window 
main.update() 
main.mainloop()

You might also like