-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathview_result.py
More file actions
101 lines (90 loc) · 5.64 KB
/
view_result.py
File metadata and controls
101 lines (90 loc) · 5.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from tkinter import *
from PIL import Image, ImageTk
from tkinter import ttk, messagebox
import sqlite3
class ViewResult:
def __init__(self, root):
self.root = root
self.root.title("Student Result Management System")
self.root.geometry("1200x480+80+170")
self.root.config(bg="white")
self.root.focus_force()
# Search Panel
self.var_search = StringVar()
self.var_id = ""
# Title
title = Label(self.root, text="View Student Results", font=("goudy old style", 20, "bold"), bg='orange', fg="#262626").place(x=10, y=15, width=1180, height=50)
# Search
self.var_search = StringVar()
lbl_search = Label(self.root, text="Search By Roll No.", font=("goudy old style", 15, 'bold'), bg='white').place(x=280, y=100)
txt_search = Entry(self.root, textvariable=self.var_search, font=("goudy old style", 15), bg='lightyellow').place(x=520, y=100, width=150)
btn_search = Button(self.root, text='Search', font=("goudy old style", 15, "bold"), bg="#03a9f4", fg="white", cursor="hand2", command=self.search).place(x=680, y=100, width=100, height=35)
btn_clear = Button(self.root, text='Clear', font=("goudy old style", 15, "bold"), bg="gray", fg="white", cursor="hand2", command=self.clear).place(x=800, y=100, width=100, height=35)
# Result Labels
lbl_roll = Label(self.root, text="Roll No", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=150, y=230, width=150, height=50)
lbl_name = Label(self.root, text="Name", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=300, y=230, width=150, height=50)
lbl_course = Label(self.root, text="Course", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=450, y=230, width=150, height=50)
lbl_marks = Label(self.root, text="Marks Obtained", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=600, y=230, width=150, height=50)
lbl_full = Label(self.root, text="Total Marks", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=750, y=230, width=150, height=50)
lbl_per = Label(self.root, text="Percentage", font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE).place(x=900, y=230, width=150, height=50)
self.roll = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.roll.place(x=150, y=280, width=150, height=50)
self.name = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.name.place(x=300, y=280, width=150, height=50)
self.course = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.course.place(x=450, y=280, width=150, height=50)
self.marks = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.marks.place(x=600, y=280, width=150, height=50)
self.full = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.full.place(x=750, y=280, width=150, height=50)
self.per = Label(self.root, font=("goudy old style", 15, 'bold'), bg='white', bd=2, relief=GROOVE)
self.per.place(x=900, y=280, width=150, height=50)
def search(self):
con = sqlite3.connect(database="rms.db")
cur = con.cursor()
try:
if self.var_search.get() == "":
messagebox.showerror("Error", "Roll No. should be required", parent=self.root)
else:
cur.execute("SELECT * FROM result WHERE roll=?", (self.var_search.get(),))
row = cur.fetchone()
if row is not None:
cur.execute("SELECT name FROM student WHERE roll=?", (self.var_search.get(),))
student = cur.fetchone()
cur.execute("SELECT name FROM course WHERE cid=?", (row[2],))
course = cur.fetchone()
# Debugging: Check values
print("Marks Obtained:", row[4])
print("Total Marks:", row[5])
print(row)
# Check if marks and total are valid integers
if row[4] is None or row[5] is None:
messagebox.showerror("Error", "Marks or Total Marks cannot be empty", parent=self.root)
return
try:
marks_obtained = int(float(row[4]))
total_marks = int(float(row[5]))
print(row)
except:
pass
per = (int(row[4]) * 100) / int(row[5]) if int(row[5]) != 0 else 0 # Avoid division by zero
self.roll.config(text=row[1])
self.name.config(text=student[0] if student else "N/A")
self.course.config(text=row[3] if row[3] else "N/A")
self.marks.config(text=row[4])
self.full.config(text=row[5])
self.per.config(text=str(round(per, 2)) + "%")
else:
messagebox.showerror("Error", "No record found", parent=self.root)
except Exception as ex:
messagebox.showerror("Error", f"Error due to {str(ex)}")
finally:
con.close()
def clear(self):
self.var_search.set("")
self.roll.config(text="")
self.name.config(text="")
self.course.config(text="")
self.marks.config(text="")
self.full.config(text="")
self.per.config(text="")