-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from rohitagr0310/main
Added GUI for the Application
- Loading branch information
Showing
8 changed files
with
125 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}" |