0% found this document useful (0 votes)
11 views4 pages

T

This document contains a Python script that creates a GUI application for generating student report cards using Tkinter. It allows users to input student details and marks, calculates total marks, percentage, and grade, and displays the results in a new window. Additionally, it provides functionality to save the report card data into a CSV file.

Uploaded by

pigapgigap
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)
11 views4 pages

T

This document contains a Python script that creates a GUI application for generating student report cards using Tkinter. It allows users to input student details and marks, calculates total marks, percentage, and grade, and displays the results in a new window. Additionally, it provides functionality to save the report card data into a CSV file.

Uploaded by

pigapgigap
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
You are on page 1/ 4

import tkinter as tk

from tkinter import messagebox, Toplevel


import csv

# Function to calculate and display the report card on a second page


def calculate_report():
try:
name = name_entry.get()
roll_no = roll_entry.get()
marks = [int(math_entry.get()), int(physics_entry.get()),
int(chemistry_entry.get()), int(cs_entry.get()), int(english_entry.get())]

total_marks = sum(marks)
percentage = total_marks / 5
grade = "A+" if percentage >= 90 else "A" if percentage >= 80 else
"B" if percentage >= 70 else "C" if percentage >= 60 else "D" if
percentage >= 50 else "F"

# Open a new window to display the result along with buttons


result_window = Toplevel(root)
result_window.title("Report Card")
result_window.geometry("350x400")
result_window.config(bg="light blue")

tk.Label(result_window, text="Student Report Card", font=("Arial",


14, "bold"), bg="light blue").pack(pady=5)
tk.Label(result_window, text=f"Student Name: {name}",
font=("Arial", 12), bg="light blue").pack()
tk.Label(result_window, text=f"Roll Number: {roll_no}", font=("Arial",
12), bg="light blue").pack()
tk.Label(result_window, text=f"Mathematics: {marks[0]}",
font=("Arial", 12), bg="light blue").pack()
tk.Label(result_window, text=f"Physics: {marks[1]}", font=("Arial",
12), bg="light blue").pack()
tk.Label(result_window, text=f"Chemistry: {marks[2]}", font=("Arial",
12), bg="light blue").pack()
tk.Label(result_window, text=f"Computer Science: {marks[3]}",
font=("Arial", 12), bg="light blue").pack()
tk.Label(result_window, text=f"English: {marks[4]}", font=("Arial",
12), bg="light blue").pack()
tk.Label(result_window, text=f"Total Marks: {total_marks}",
font=("Arial", 12), bg="light blue").pack()
tk.Label(result_window, text=f"Percentage: {percentage:.2f}%",
font=("Arial", 12), bg="light blue").pack()
tk.Label(result_window, text=f"Grade: {grade}", font=("Arial", 12,
"bold"), fg="blue", bg="light blue").pack()

# Buttons inside result window


tk.Button(result_window, text="Save Report",
command=save_report, font=("Arial", 10, "bold"),
bg="white").pack(pady=10)

except ValueError:
messagebox.showerror("Input Error", "Please enter valid marks
(0-100).")

# Function to save report card to CSV file


def save_report():
try:
name = name_entry.get()
roll_no = roll_entry.get()
marks = [math_entry.get(), physics_entry.get(),
chemistry_entry.get(), cs_entry.get(), english_entry.get()]
total_marks = sum([int(m) for m in marks])
percentage = total_marks / 5
grade = "A+" if percentage >= 90 else "A" if percentage >= 80 else
"B" if percentage >= 70 else "C" if percentage >= 60 else "D" if
percentage >= 50 else "F"

with open("student_records.csv", "a", newline="") as file:


writer = csv.writer(file)
writer.writerow([name, roll_no, *marks, total_marks,
f"{percentage:.2f}%", grade])
messagebox.showinfo("Success", "Student Report Saved
Successfully!")

except ValueError:
messagebox.showerror("Error", "Please enter valid data before
saving.")

# GUI Setup
root = tk.Tk()
root.title("Student Report Card")
root.geometry("400x500")
root.config(bg="light blue")

# Title Label
tk.Label(root, text="Student Report Card", font=("Arial", 16, "bold"),
bg="light blue").pack(pady=10)

tk.Label(root, text="Student Name:", bg="light blue").pack()


name_entry = tk.Entry(root)
name_entry.pack()

tk.Label(root, text="Roll Number:", bg="light blue").pack()


roll_entry = tk.Entry(root)
roll_entry.pack()

tk.Label(root, text="Enter Marks (out of 100)", bg="light blue",


font=("Arial", 10, "bold")).pack(pady=5)

tk.Label(root, text="Mathematics:", bg="light blue").pack()


math_entry = tk.Entry(root)
math_entry.pack()

tk.Label(root, text="Physics:", bg="light blue").pack()


physics_entry = tk.Entry(root)
physics_entry.pack()
tk.Label(root, text="Chemistry:", bg="light blue").pack()
chemistry_entry = tk.Entry(root)
chemistry_entry.pack()

tk.Label(root, text="Computer Science:", bg="light blue").pack()


cs_entry = tk.Entry(root)
cs_entry.pack()

tk.Label(root, text="English:", bg="light blue").pack()


english_entry = tk.Entry(root)
english_entry.pack()

# Button Frame for better alignment


button_frame = tk.Frame(root, bg="light blue")
button_frame.pack(pady=10)

tk.Button(button_frame, text="Calculate Report",


command=calculate_report, font=("Arial", 10, "bold"),
bg="white").pack(side="left", padx=10)

# Start GUI loop


root.mainloop()

You might also like