Skip to content

Commit

Permalink
Merge pull request #9 from rohitagr0310/main
Browse files Browse the repository at this point in the history
Added GUI for the Application
  • Loading branch information
rohitagr0310 authored Oct 8, 2023
2 parents 645197f + 9198ac6 commit 0130fd9
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 23 deletions.
46 changes: 23 additions & 23 deletions CS_Source Code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
Binary file added GUI/__pycache__/file_operations.cpython-311.pyc
Binary file not shown.
Binary file added GUI/__pycache__/student.cpython-311.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions GUI/file_operations.py
Original file line number Diff line number Diff line change
@@ -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!"]
61 changes: 61 additions & 0 deletions GUI/gui.py
Original file line number Diff line number Diff line change
@@ -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()
Binary file added GUI/stud.dat
Binary file not shown.
16 changes: 16 additions & 0 deletions GUI/student.py
Original file line number Diff line number Diff line change
@@ -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}"
Binary file modified stud.dat
Binary file not shown.

0 comments on commit 0130fd9

Please sign in to comment.