diff --git a/CS_Source Code.py b/CS_Source Code.py index 6a8d628..da0891c 100644 --- a/CS_Source Code.py +++ b/CS_Source Code.py @@ -16,31 +16,31 @@ class used class student(object): - def __int__(s): - s.roll = 0 - s.name = "" - s.per = 0 - - def add_rec(s): - s.roll = int(input("Enter roll number: ")) - s.name = input("Enter name: ") - s.name = s.name.upper() - s.per = float(input("Enter percentage: ")) - - def disp_rec(s): - print("roll number: ", s.roll) - print("name: ", s.name) - print("percentage: ", s.per) - - def display_rec(s): - print("%-10s" % s.roll, "%-20s" % s.name, "%-10s" % s.per) + def __init__(self): + self.roll = 0 + self.name = "" + self.per = 0 + + def add_rec(self): + self.roll = int(input("Enter roll number: ")) + self.name = input("Enter name: ") + self.name = self.name.upper() + self.per = float(input("Enter percentage: ")) + + def disp_rec(self): + print("roll number: ", self.roll) + print("name: ", self.name) + print("percentage: ", self.per) + + def display_rec(self): + print("%-10s" % self.roll, "%-20s" % self.name, "%-10s" % self.per) # print("in display_rec") - def modify_rec(s): - s.roll = int(input("Enter new roll number: ")) - s.name = input("Enter new name: ") - s.name = s.name.upper() - s.per = float(input("Enter new percentage: ")) + def modify_rec(self): + self.roll = int(input("Enter new roll number: ")) + self.name = input("Enter new name: ") + self.name = self.name.upper() + self.per = float(input("Enter new percentage: ")) def write_record(): diff --git a/GUI/__pycache__/file_operations.cpython-311.pyc b/GUI/__pycache__/file_operations.cpython-311.pyc new file mode 100644 index 0000000..20aaa4d Binary files /dev/null and b/GUI/__pycache__/file_operations.cpython-311.pyc differ diff --git a/GUI/__pycache__/student.cpython-311.pyc b/GUI/__pycache__/student.cpython-311.pyc new file mode 100644 index 0000000..3cddac5 Binary files /dev/null and b/GUI/__pycache__/student.cpython-311.pyc differ diff --git a/GUI/file_operations.py b/GUI/file_operations.py new file mode 100644 index 0000000..9f7c752 --- /dev/null +++ b/GUI/file_operations.py @@ -0,0 +1,25 @@ +# file_operations.py +import pickle + + +def write_record(student): + try: + with open("stud.dat", "ab") as file: + pickle.dump(student, file) + return "Record added in file!" + except Exception as e: + return f"Error: {str(e)}" + + +def display_all_records(): + records = [] + try: + with open("stud.dat", "rb") as file: + while True: + student = pickle.load(file) + records.append(student.display_record()) + return records + except EOFError: + return records + except IOError: + return ["File could not be opened!"] diff --git a/GUI/gui.py b/GUI/gui.py new file mode 100644 index 0000000..f86dbf3 --- /dev/null +++ b/GUI/gui.py @@ -0,0 +1,61 @@ +# gui.py +import tkinter as tk +import student +import file_operations + + +def write_record(): + try: + roll = int(roll_entry.get()) + name = name_entry.get() + per = float(per_entry.get()) + + student_obj = student.Student() + student_obj.add_record(roll, name, per) + + result_label.config(text=file_operations.write_record(student_obj)) + + except Exception as e: + result_label.config(text=str(e)) + + +def display_all(): + result_text.delete(1.0, tk.END) + + records = file_operations.display_all_records() + + for record in records: + result_text.insert(tk.END, record + "\n\n") + + +app = tk.Tk() +app.title("Student Record Management") + +frame = tk.Frame(app) +frame.pack(padx=20, pady=20) + +tk.Label(frame, text="Roll Number:").grid(row=0, column=0) +tk.Label(frame, text="Name:").grid(row=1, column=0) +tk.Label(frame, text="Percentage:").grid(row=2, column=0) + +roll_entry = tk.Entry(frame) +name_entry = tk.Entry(frame) +per_entry = tk.Entry(frame) + +roll_entry.grid(row=0, column=1) +name_entry.grid(row=1, column=1) +per_entry.grid(row=2, column=1) + +add_button = tk.Button(frame, text="Add Record", command=write_record) +add_button.grid(row=3, column=0, columnspan=2) + +display_button = tk.Button(frame, text="Display All Records", command=display_all) +display_button.grid(row=4, column=0, columnspan=2) + +result_label = tk.Label(frame, text="", wraplength=300) +result_label.grid(row=5, column=0, columnspan=2) + +result_text = tk.Text(frame, height=10, width=40) +result_text.grid(row=6, column=0, columnspan=2) + +app.mainloop() diff --git a/GUI/stud.dat b/GUI/stud.dat new file mode 100644 index 0000000..1d97c76 Binary files /dev/null and b/GUI/stud.dat differ diff --git a/GUI/student.py b/GUI/student.py new file mode 100644 index 0000000..b3bbdc8 --- /dev/null +++ b/GUI/student.py @@ -0,0 +1,16 @@ +# student.py + + +class Student: + def __init__(self): + self.roll = 0 + self.name = "" + self.per = 0 + + def add_record(self, roll, name, per): + self.roll = roll + self.name = name.upper() + self.per = per + + def display_record(self): + return f"Roll Number: {self.roll}\nName: {self.name}\nPercentage: {self.per}" diff --git a/stud.dat b/stud.dat index 1fe08aa..f7a90c5 100644 Binary files a/stud.dat and b/stud.dat differ