Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Turtle
  • Python PIL
  • Python Program
  • Python Projects
  • Python DataBase
  • Python Flask
  • Python Django
  • Numpy
  • Pandas
  • Python Database
  • Data Science With Python
  • Machine Learning with Python
  • Django
  • Flask
  • R
Open In App
Next Article:
Student Results Management System Using Tkinter
Next article icon

Student Results Management System Using Tkinter

Last Updated : 10 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In this tutorial, we will create a simple exam result management system using Tkinter for the GUI and SQLite for the database. We will start by creating two files in the project directory: a Python file for the code (mainprogram.py) and a database file (studentrecords.db). Let's discuss the code for the system.

Student Results Management System Using Tkinter

Let's see the steps to create a Student Results Management System using Tkinter:

Importing the libraries

Python
from tkinter import * import sqlite3 import time 

Creating the Database

We'll create an SQLite database called studentrecords.db and a table named StudentData to store student information.

Python
con = sqlite3.connect('studentrecords.db') c = con.cursor() c.execute("""CREATE TABLE IF NOT EXISTS StudentData(                 Name TEXT,                 Roll NUMBER,                 Gender TEXT,                 Maths NUMBER,                 Physics NUMBER,                 Chemistry NUMBER)""") con.commit() con.close() 

Building the GUI

Now, let's start building the GUI using Tkinter.

Python
root = Tk() root.geometry('1000x500') root.title('Exam Records') var = IntVar()  # Creating Labels Label(root, font=("Arial", 15), fg="purple", text="Exam Records").place(x=210, y=30) Label(root, font=("Helvetica", 12), fg="purple", text="Name").place(x=69, y=120) Label(root, font=("Helvetica", 12), fg="purple", text="Gender").place(x=69, y=164) Label(root, font=("Helvetica", 12), fg="purple", text="Roll Number").place(x=69, y=208) Label(root, font=("Helvetica", 12), fg="purple", text="Mathematics").place(x=69, y=250) Label(root, font=("Helvetica", 12), fg="purple", text="Physics").place(x=69, y=290) Label(root, font=("Helvetica", 12), text="Chemistry", fg="purple").place(x=69, y=330)  # Creating Entry Boxes name = Entry(root, font=("Helvetica", 12), width=27, bg="lightblue") rbutton1 = Radiobutton(root, font=("Helvetica", 12), fg="red", variable=var, value=1, text="Male") rbutton2 = Radiobutton(root, font=("Helvetica", 12), fg="green", variable=var, value=2, text="Female") rollno = Entry(root, font=("Helvetica", 12), width=27, bg="lightblue") maths = Entry(root, font=("Helvetica", 12), width=27, bg="lightblue") physics = Entry(root, font=("Helvetica", 12), width=27, bg="lightblue") chemistry = Entry(root, font=("Helvetica", 12), width=27, bg="lightblue")  # Placing Widgets name.place(x=170, y=122) rbutton1.place(x=170, y=164) rbutton2.place(x=250, y=164) rollno.place(x=170, y=207) maths.place(x=170, y=249) physics.place(x=170, y=289) chemistry.place(x=170, y=329)  # Create Buttons Button(root, font=("Arial", 15), fg="white", bg="purple", text="Submit", borderwidth=0, command=lambda: clicksubmit()).place(x=242, y=369) Button(root, font=("Helvetica", 12), bg="green", fg="white", text="Delete A Record", borderwidth=0, command=recdelete).place(x=220, y=410) Button(root, font=("Helvetica", 12), text="Clear Database", bg="red", fg="white", borderwidth=0, command=clearall).place(x=223, y=450) 

Adding Student Records

We will create a function clicksubmit() to handle the submission of new student records.

Python
def clicksubmit():     con = sqlite3.connect('studentrecords.db')     c = con.cursor()      studentname = name.get()     rollnum = rollno.get()     math_marks = maths.get()     phy_marks = physics.get()     chem_marks = chemistry.get()     gender = "Male" if var.get() == 1 else "Female"      c.execute("""INSERT INTO StudentData(Name, Roll, Gender, Maths, Physics, Chemistry) VALUES(?,?,?,?,?,?)""",               (studentname, rollnum, gender, math_marks, phy_marks, chem_marks))      con.commit()     con.close()      name.delete(0, END)     rollno.delete(0, END)     maths.delete(0, END)     physics.delete(0, END)     chemistry.delete(0, END) 

Deleting a Record

Next, we'll create functions to delete a specific student record or clear the entire database.

Python
def clickok():     con = sqlite3.connect('studentrecords.db')     c = con.cursor()     num = int(e.get())     try:         c.execute(f'DELETE FROM StudentData WHERE Roll={num}')         con.commit()         Label(deletewin, fg="red", text="Deleted Successfully", font=("Helvetica", 10)).place(x=6, y=115)     finally:         deletewin.after(3000, lambda: deletewin.destroy())  def recdelete():     global deletewin     deletewin = Toplevel(root)     global e     e = Entry(deletewin, font=("Helvetica", 12))     e.place(x=5, y=40)     Label(deletewin, font=("Helvetica", 12), text="Please Enter Roll No",           fg="purple").place(x=5, y=10)     Button(deletewin, text="OK", command=lambda: clickok(), font=("Helvetica", 10),             bg="lightpink", fg="purple", borderwidth=0).place(x=100, y=150)  def yesclk():     con = sqlite3.connect('studentrecords.db')     c = con.cursor()     c.execute("DELETE FROM StudentData")     con.commit()     con.close()     newwind.destroy()  def clearall():     global newwind     newwind = Toplevel(root)     newwind.geometry('200x200')     Button(newwind, font=("Helvetica", 12), text="Yes", borderwidth=0, bg="lightpink",             fg="purple", command=yesclk).place(x=7, y=160)     Button(newwind, font=("Helvetica", 12), text="No", borderwidth=0, bg="lightpink",             fg="purple", command=lambda: newwind.destroy()).place(x=160, y=160)     Label(newwind, font=("Arial", 15), text="Are You Sure?", fg="purple").place(x=15, y=25) 

Viewing Student Records

Finally, let's add functionality to display student marks sorted by subject.

Python
def display_results(subject):     newwind = Toplevel(root)     Label(newwind, text="Name", font=("Helvetica", 10), fg="purple", bg="lightpink").place(x=2, y=0)     Label(newwind, text="Roll Number", font=("Helvetica", 10), fg="purple", bg="lightpink").place(x=152, y=0)     Label(newwind, text="Marks Obtained", font=("Helvetica", 10), fg="purple", bg="lightpink").place(x=302, y=0)     newwind.geometry('400x400')      con = sqlite3.connect('studentrecords.db')     c = con.cursor()     rows = c.execute(f"SELECT Name, Roll, {subject} FROM StudentData ORDER BY {subject} desc")      y1 = 30     for row in rows:         s_name, roll, marks = row         Label(newwind, font=("Helvetica", 10), fg="purple", bg="lightpink", text=s_name).place(x=2, y=y1)         Label(newwind, font=("Helvetica", 10), fg="purple", bg="lightpink", text=str(roll)).place(x=152, y=y1)         Label(newwind, font=("Helvetica", 10), fg="purple", bg="lightpink", text=str(marks)).place(x=302, y=y1)         y1 += 30  Button(root, text="Display Maths Results", bg="purple", fg="white", font=("Helvetica", 15),         command=lambda: display_results("Maths"), borderwidth=0).place(x=500, y=50) Button(root, text="Display Physics Results", bg="purple", fg="white", font=("Helvetica", 15),        command=lambda: display_results("Physics"), borderwidth=0).place(x=500, y=95) Button(root, text="Display Chemistry Results", bg="purple", fg="white", font=("Helvetica", 15),         command=lambda: display_results("Chemistry"), borderwidth=0).place(x=500, y=140) 

Running the Application

Finally, we need to run the Tkinter main loop to display our GUI.

Python
root.mainloop() 

This is the complete code for the system

Complete Code

Python
from tkinter import * import sqlite3 import time  def clickok():     con=sqlite3.connect('studentrecords.db')     c=con.cursor()     num=e.get()     num=int(num)     print(num)     try:         c.execute(f'DELETE FROM StudentData WHERE Roll={num}')         con.commit()         button.config(command=lambda:button.pack_forget())         l2=Label(deletewin,fg="red",text="Deleted Successfully",font=("Helvetica",10)).place(x=6,y=115)           # l2=Label(deletewin,fg="red",text="No Such Record Found",font=("Helvetica",10)).place(x=6,y=115)              finally:         deletewin.after(3000,lambda:deletewin.destroy())        def recdelete():     global deletewin     deletewin=Toplevel(root)     global e     e=Entry(deletewin,font=("Helvetica",12))     e.place(x=5,y=40)     l=Label(deletewin,font=("Helvetica",12),text="Please Enter Roll No",fg="purple").place(x=5,y=10)     global button     button=Button(deletewin,text="OK",command=lambda:clickok(),font=("Helvetica",10),                   bg="lightpink",fg="purple",borderwidth=0).place(x=100,y=150)      def yesclk():     con=sqlite3.connect('studentrecords.db')     c=con.cursor()     c.execute("DELETE FROM StudentData")     newwind.destroy()     con.commit()     con.close() def clearall():     global newwind     newwind=Toplevel(root)     newwind.geometry('200x200')     yesbtn=Button(newwind,font=("Helvetica",12),text="Yes",borderwidth=0,bg="lightpink",                   fg="purple",command=yesclk).place(x=7,y=160)     nobtn=Button(newwind,font=("Helvetica",12),text="No",borderwidth=0,bg="lightpink",                  fg="purple",command=lambda:newwind.destroy()).place(x=160,y=160)     label1=Label(newwind,font=("Arial",15),text="Are You Sure?",fg="purple").place(x=15,y=25)  def clicksubmit():     print("Called Function")     con=sqlite3.connect('studentrecords.db')     c=con.cursor()      studentname=name.get()     rollnum=rollno.get()     math_marks=maths.get()     phy_marks=physics.get()     chem_marks=chemistry.get()     gender=""     gen=var.get()     if(gen==1):         gender+="Male"     else:         gender+="Female"         c.execute("""INSERT INTO StudentData(Name,Roll,Gender,Maths,Physics,Chemistry) VALUES(?,?,?,?,?,?)""",               (studentname,rollnum,gender,math_marks,phy_marks,chem_marks))     rows=c.execute("SELECT * from StudentData")     print(type(rows))     for row in rows:         print(type(row))         print(row)         # print("Unable To Enter")      con.commit()     name.delete(0,END)     rollno.delete(0,END)     maths.delete(0,END)     physics.delete(0,END)     chemistry.delete(0,END) root=Tk() root.geometry('1000x500') root.iconbitmap('ER.ico') root.title('Exam Records') var=IntVar() global con con=sqlite3.connect('studentrecords.db') c=con.cursor() c.execute("""CREATE TABLE IF NOT EXISTS StudentData(Name TEXT,Roll NUMBER,Gender TEXT,\ 								Maths NUMBER,Physics NUMBER,Chemistry NUMBER)""") # Creating Labels header=Label(root,font=("Arial",15),fg="purple",text="Exam Records").place(x=210,y=30) name_label=Label(root,font=("Helvetica",12),fg="purple",text="Name").place(x=69,y=120) gender=Label(root,font=("Helvetica",12),fg="purple",text="Gender").place(x=69,y=164) roll=Label(root,font=("Helvetica",12),fg="purple",text="Roll Number").place(x=69,y=208) math_sub=Label(root,font=("Helvetica",12),fg="purple",text="Mathematics").place(x=69,y=250) phy_sub=Label(root,font=("Helvetica",12),fg="purple",text="Physics").place(x=69,y=290) chem_sub=Label(root,font=("Helvetica",12),text="Chemistry",fg="purple").place(x=69,y=330)  # Creating Entry Boxes global name,rbutton1,rbutton2,rollno,maths,physics,chemistry name=Entry(root,font=("Helvetica",12),width=27,bg="lightblue") rbutton1=Radiobutton(root,font=("Helvetica",12),fg="red",variable=var,value=1,text="Male") rbutton2=Radiobutton(root,font=("Helvetica",12),fg="green",variable=var,value=2,text="Female") rollno=Entry(root,font=("Helvetica",12),width=27,bg="lightblue") maths=Entry(root,font=("Helvetica",12),width=27,bg="lightblue") physics=Entry(root,font=("Helvetica",12),width=27,bg="lightblue") chemistry=Entry(root,font=("Helvetica",12),width=27,bg="lightblue") # Placing Widgets name.place(x=170,y=122) rbutton1.place(x=170,y=164) rbutton2.place(x=250,y=164) rollno.place(x=170,y=207) maths.place(x=170,y=249) physics.place(x=170,y=289) chemistry.place(x=170,y=329) # Create a Submit Button , Delete Record , Clear Data Base submit=Button(root,font=("Arial",15),fg="white",bg="purple",text="Submit",borderwidth=0,               command=lambda:clicksubmit()).place(x=242,y=369) con.commit() con.close() delete=Button(root,font=("Helvetica",12),bg="green",fg="white",text="Delete A Record",               borderwidth=0,command=recdelete).place(x=220,y=410) frame=Frame(root,bg="lightpink",width=500,height=500).place(x=500,y=0) clearEntry=Button(root,font=("Helvetica",12),text="Clear Database",bg="red",fg="white",                   borderwidth=0,command=clearall).place(x=223,y=450) # Frame Buttons def mathres():      print("Inside Math")     newwind=Toplevel(root)     lab_header1=Label(newwind,text="Name",font=("Helvetica",10),fg="purple",bg="lightpink").place(x=2,y=0)     lab_header2=Label(newwind,text="Roll Number",font=("Helvetica",10),fg="purple",bg="lightpink").place(x=152,y=0)     lab_header3=Label(newwind,text="Marks Obtained",font=("Helvetica",10),fg="purple",bg="lightpink").place(x=302,y=0)     newwind.geometry('400x400')     con=sqlite3.connect('studentrecords.db')     c=con.cursor()     rows=c.execute("SELECT Name,Roll,Maths FROM StudentData ORDER BY Maths desc")     x1=2      y1=30     for row in rows:         s_name=row[0]         roll=row[1]         math=row[2]         lab1=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=s_name).place(x=x1,y=y1)         lab2=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(roll)).place(x=x1+150,y=y1)         lab3=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(math)).place(x=x1+300,y=y1)         y1+=30  def chemres():     print("Inside Chem")     newwind=Toplevel(root)     lab_header1=Label(newwind,text="Name",font=("Helvetica",10),fg="purple",                       bg="lightpink").place(x=2,y=0)     lab_header2=Label(newwind,text="Roll Number",font=("Helvetica",10),fg="purple",                       bg="lightpink").place(x=152,y=0)     lab_header3=Label(newwind,text="Marks Obtained",font=("Helvetica",10),fg="purple",                       bg="lightpink").place(x=302,y=0)     newwind.geometry('400x400')     con=sqlite3.connect('studentrecords.db')     c=con.cursor()     rows=c.execute("SELECT Name,Roll,Chemistry FROM StudentData ORDER BY Chemistry desc")     x1=2      y1=30     for row in rows:         s_name=row[0]         roll=row[1]         math=row[2]         lab1=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=s_name).place(x=x1,y=y1)         lab2=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(roll)).place(x=x1+150,y=y1)         lab3=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(math)).place(x=x1+300,y=y1)         y1+=30   def phyres():     print("Inside Physics")     newwind=Toplevel(root)     lab_header1=Label(newwind,text="Name",font=("Helvetica",10),                       fg="purple",bg="lightpink").place(x=2,y=0)     lab_header2=Label(newwind,text="Roll Number",font=("Helvetica",10),                       fg="purple",bg="lightpink").place(x=152,y=0)     lab_header3=Label(newwind,text="Marks Obtained",font=("Helvetica",10),                       fg="purple",bg="lightpink").place(x=302,y=0)     newwind.geometry('400x400')     con=sqlite3.connect('studentrecords.db')     c=con.cursor()     rows=c.execute("SELECT Name,Roll,Physics FROM StudentData ORDER BY Physics desc")     x1=2      y1=30     for row in rows:         s_name=row[0]         roll=row[1]         math=row[2]         lab1=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=s_name).place(x=x1,y=y1)         lab2=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(roll)).place(x=x1+150,y=y1)         lab3=Label(newwind,font=("Helvetica",10),fg="purple",bg="lightpink",                    highlightcolor="purple",text=str(math)).place(x=x1+300,y=y1)         y1+=30  button1=Button(frame,text="Display Maths Results",bg="purple",fg="white",font=("Helvetica",15),                command=lambda:mathres(),borderwidth=0).place(x=500,y=50) button2=Button(frame,text="Display Physics Results",bg="purple",fg="white",font=("Helvetica",15),                command=phyres,borderwidth=0).place(x=500,y=95) button3=Button(frame,text="Display Chemistry Results",bg="purple",fg="white",font=("Helvetica",15),                borderwidth=0,command=chemres).place(x=500,y=140)  root.mainloop() 

Output

Optionally we may add an icon for the application (.ico file) . Below is a screenshot of the home screen of the application.

temp1

Conclusion

In this article, we discussed about building a simple exam result management system using Tkinter for the GUI and SQLite for the database. This system allows you to add student records, delete specific records, clear the entire database, and display student marks sorted by subject. Further functionalities including adding graphs , exporting data to a file etc. can be added to enhance the application.


Next Article
Student Results Management System Using Tkinter

H

harshsingh7578
Improve
Article Tags :
  • Python
  • Python-tkinter
  • Python Tkinter-projects
Practice Tags :
  • python

Similar Reads

    College Management System using Django - Python Project
    In this article, we are going to build College Management System using Django and will be using dbsqlite database. In the times of covid, when education has totally become digital, there comes a need for a system that can connect teachers, students, and HOD and that was the motivation behind buildin
    15+ min read
    Loading Images in Tkinter using PIL
    In this article, we will learn how to load images from user system to Tkinter window using PIL module. This program will open a dialogue box to select the required file from any directory and display it in the tkinter window.Install the requirements - Use this command to install Tkinter : pip instal
    3 min read
    Create First GUI Application using Python-Tkinter
    We are now stepping into making applications with graphical elements, we will learn how to make cool apps and focus more on its GUI(Graphical User Interface) using Tkinter.What is Tkinter?Tkinter is a Python Package for creating GUI applications. Python has a lot of GUI frameworks, but Tkinter is th
    12 min read
    Python | Create a GUI Marksheet using Tkinter
    Create a python GUI mark sheet. Where credits of each subject are given, enter the grades obtained in each subject and click on Submit. The credits per subject, the total credits as well as the SGPA are displayed after being calculated automatically. Use Tkinter to create the GUI interface.  Refer t
    8 min read
    Create Table Using Tkinter
    Python offers multiple options for developing a GUI (Graphical User Interface). Out of all the GUI methods, Tkinter is the most commonly used method. It is a standard Python interface to the Tk GUI toolkit shipped with Python. Python with Tkinter is the fastest and easiest way to create GUI applicat
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences