-
Notifications
You must be signed in to change notification settings - Fork 151
/
Copy pathCGPA_calculator_tkinter.py
39 lines (28 loc) · 1005 Bytes
/
CGPA_calculator_tkinter.py
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
import tkinter as tk
def calculate_cgpa():
try:
subjects = int(subjects_entry.get())
grades = [int(grade) for grade in grades_entry.get().split(",")]
total_grade_points = sum(grades)
cgpa = total_grade_points / subjects
result_label.config(text=f"CGPA: {cgpa:.2f}")
except (ValueError, ZeroDivisionError):
result_label.config(text="Invalid input!")
# Create the main window
root = tk.Tk()
root.title("CGPA Calculator")
# Create the form elements
subjects_label = tk.Label(root, text="Number of Subjects:")
subjects_label.pack()
subjects_entry = tk.Entry(root)
subjects_entry.pack()
grades_label = tk.Label(root, text="Grades (Separated by comma):")
grades_label.pack()
grades_entry = tk.Entry(root)
grades_entry.pack()
calculate_button = tk.Button(root, text="Calculate CGPA", command=calculate_cgpa)
calculate_button.pack()
result_label = tk.Label(root, text="")
result_label.pack()
# Run the application
root.mainloop()