Download as pdf or txt
Download as pdf or txt
You are on page 1of 11

Computer Science Journal 2023-24

Computer Science 083

Name: - Neal Balsara


Class & section: - XI A
Project: - Computer Science Practical Journal
ACKNOWLEDGEMENT
I would like to express my sincere gratitude to all those who have contributed
to the successful completion of my Class 11 Computer Science project. My
heartfelt thanks go to my computer science teacher MRS Ashwini ma’am for
invaluable guidance and support throughout the project. I am also indebted to
my classmates for their collaborative spirit and insightful discussions. Special
appreciation is extended to my parents for their unwavering encouragement
and understanding during this academic endeavour. Additionally, I
acknowledge the wealth of online resources and literature that enriched my
understanding and allowed me to delve deeper into the subject matter. This
project has been a significant learning experience, and I am thankful for the
collective effort that made it possible.
Practical No. 1
Task 1: - Write a program to make a student management system where you
will make for student attendance using tkinter and python GUI.
Source code: -
import tkinter as tk
from tkinter import ttk, messagebox

class StudentManagementSystem:
def __init__(self, root):
self.root = root
self.root.title("Student Management System")

# Student data
self.students = []

# Attendance data
self.attendance_data = {}

# Widgets
self.name_label = ttk.Label(root, text="Student Name:")
self.name_entry = ttk.Entry(root)

# Add Student button


self.add_button = ttk.Button(root, text="Add Student",
command=self.add_student, width=20)
self.add_button.place(x=10, y=40)
# Mark Attendance button
self.mark_attendance_button = ttk.Button(root, text="Mark Attendance",
command=self.mark_attendance, width=20)
self.mark_attendance_button.place(x=10, y=70)

# View Attendance button


self.view_attendance_button = ttk.Button(root, text="View Attendance",
command=self.view_attendance, width=20)
self.view_attendance_button.place(x=10, y=100)

# Grid layout
self.name_label.grid(row=0, column=0, pady=10, padx=10, sticky=tk.W)
self.name_entry.grid(row=0, column=1, pady=10, padx=10, sticky=tk.W)

def add_student(self):
student_name = self.name_entry.get()
if student_name:
self.students.append(student_name)
self.name_entry.delete(0, tk.END)
messagebox.showinfo("Success", f"Student '{student_name}' added
successfully.")
else:
messagebox.showerror("Error", "Please enter a student name.")

def mark_attendance(self):
if not self.students:
messagebox.showerror("Error", "No students added. Please add
students first.")
return

attendance_window = tk.Toplevel(self.root)
attendance_window.title("Mark Attendance")

for i, student in enumerate(self.students):


ttk.Label(attendance_window, text=student).grid(row=i, column=0,
pady=5)
attendance_status = tk.StringVar(value="Unmarked")
ttk.Radiobutton(attendance_window, text="Present",
variable=attendance_status, value="Present", command=lambda i=i:
self.update_attendance_data(i, attendance_status)).grid(row=i, column=1,
pady=5)
ttk.Radiobutton(attendance_window, text="Absent",
variable=attendance_status, value="Absent", command=lambda i=i:
self.update_attendance_data(i, attendance_status)).grid(row=i, column=2,
pady=5)

ttk.Button(attendance_window, text="Submit Attendance",


command=lambda:
self.submit_attendance(attendance_window)).grid(row=len(self.students),
column=0, columnspan=3, pady=10)

def update_attendance_data(self, index, attendance_status):


student = self.students[index]
self.attendance_data[student] = attendance_status.get()

def submit_attendance(self, attendance_window):


attendance_window.destroy()
messagebox.showinfo("Success", "Attendance marked successfully.")

def view_attendance(self):
if not self.students:
messagebox.showerror("Error", "No students added. Please add
students first.")
return

report_window = tk.Toplevel(self.root)
report_window.title("Attendance Report")

ttk.Label(report_window, text="Student").grid(row=0, column=0, pady=5)


ttk.Label(report_window, text="Attendance").grid(row=0, column=1,
pady=5)

for i, student in enumerate(self.students):


ttk.Label(report_window, text=student).grid(row=i + 1, column=0,
pady=5)
attendance_status = self.attendance_data.get(student, "Unmarked")
ttk.Label(report_window, text=attendance_status).grid(row=i + 1,
column=1, pady=5)

if __name__ == "__main__":
root = tk.Tk()
app = StudentManagementSystem(root)
root.mainloop()
import tkinter as tk: This line imports the Tkinter library and aliases it
as tk for easier reference.

from tkinter import ttk, messagebox: Imports specific modules (ttk


for themed Tkinter widgets, and messagebox for displaying pop-up
messages) from Tkinter.

class StudentManagementSystem:: Defines a class named


StudentManagementSystem to encapsulate the functionality of the
student management application.

def __init__(self, root):: Initializes the class instance, taking the main
Tkinter window (root) as a parameter.

self.root = root: Stores the main window reference as an instance


variable.

self.root.title("Student Management System"): Sets the title of the


main window.

self.students = []: Initializes an empty list to store student names.

self.attendance_data = {}: Initializes an empty dictionary to store


attendance data.

self.name_label = ttk.Label(root, text="Student Name:"): Creates a


labeled widget for displaying "Student Name."
self.name_entry = ttk.Entry(root): Creates an entry widget for
entering student names.

self.add_button = ttk.Button(root, text="Add Student",


command=self.add_student, width=20): Creates a button labeled
"Add Student" with a command to call the add_student method.

self.add_button.place(x=10, y=40): Places the "Add Student" button


at coordinates (10, 40) within the main window.

self.mark_attendance_button = ttk.Button(root, text="Mark


Attendance", command=self.mark_attendance, width=20): Creates a
button for marking attendance.

self.mark_attendance_button.place(x=10, y=70): Places the "Mark


Attendance" button at coordinates (10, 70) within the main window.

self.view_attendance_button = ttk.Button(root, text="View


Attendance", command=self.view_attendance, width=20): Creates a
button for viewing attendance.

self.view_attendance_button.place(x=10, y=100): Places the "View


Attendance" button at coordinates (10, 100) within the main window.

self.name_label.grid(row=0, column=0, pady=10, padx=10,


sticky=tk.W): Places the "Student Name" label using the grid layout.
self.name_entry.grid(row=0, column=1, pady=10, padx=10,
sticky=tk.W): Places the student name entry widget using the grid
layout.

This is just an overview of the initialization part. The subsequent


methods (add_student, mark_attendance, update_attendance_data,
submit_attendance, and view_attendance) handle specific
functionalities of adding students, marking attendance, updating
data, submitting attendance, and viewing attendance, respectively.
Each method is designed to respond to user interactions, ensuring
the smooth functioning of the student management system.

You might also like