-
Notifications
You must be signed in to change notification settings - Fork 0
/
CGPA calculator.py
125 lines (107 loc) · 3.79 KB
/
CGPA calculator.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from tkinter import *
from tkinter.ttk import *
from pkgutil import *
# creating the main window named root
root = Tk()
# giving title to the main window
root.title("CGPA Calculator")
# Open window having dimension 100x100
root.geometry('600x600')
#defining the calculation command
def calculate():
#total credits of the semester
c1 = float(txt1.get("1.0", "end-1c"))
c2 = float(txt3.get("1.0", "end-1c"))
c3 = float(txt5.get("1.0", "end-1c"))
c4 = float(txt7.get("1.0", "end-1c"))
c5 = float(txt9.get("1.0", "end-1c"))
c6 = float(txt11.get("1.0", "end-1c"))
c7 = float(txt13.get("1.0", "end-1c"))
c8 = float(txt15.get("1.0", "end-1c"))
#SGPA for each semester
g1 = float(txt2.get("1.0", "end-1c"))
g2 = float(txt4.get("1.0", "end-1c"))
g3 = float(txt4.get("1.0", "end-1c"))
g4 = float(txt6.get("1.0", "end-1c"))
g5 = float(txt8.get("1.0", "end-1c"))
g6 = float(txt10.get("1.0", "end-1c"))
g7 = float(txt12.get("1.0", "end-1c"))
g8 = float(txt14.get("1.0", "end-1c"))
cgpa = ((c1*g1)+(c2*g2)+(c3*g3)+(c4*g4)+(c5*g5)+(c6*g6)+(c7*g7)+(c8*g8))/(c1+c2+c3+c4+c5+c6+c7+c8)
label11.config(text="CGPA is :" + str(cgpa))
#placing the elements:
# Sem 1
label1 = Label(root, text ="SEM 1").place(x=30, y=70)
label2 = Label(root, text ="Credits").place(x=80, y=40)
label3 = Label(root, text ="SGPA").place(x=160, y=40)
txt1 = Text(root, height = 1, width = 5)
txt1.place(x=80, y=70)
txt2 = Text(root, height = 1, width = 5)
txt2.place(x=160, y=70)
# Sem 2
label4 = Label(root, text ="SEM 2").place(x=30, y=120)
txt3 = Text(root, height = 1, width = 5)
txt3.place(x=80, y=120)
txt4 = Text(root, height = 1, width = 5)
txt4.place(x=160, y=120)
# Sem 3
label5 = Label(root, text ="SEM 3").place(x=30, y=160)
txt5 = Text(root, height = 1, width = 5)
txt5.place(x=80, y=160)
txt6 = Text(root, height = 1, width = 5)
txt6.place(x=160, y=160)
# Sem 4
label6 = Label(root, text ="SEM 4").place(x=30, y=200)
txt7 = Text(root, height = 1, width = 5)
txt7.place(x=80, y=200)
txt8 = Text(root, height = 1, width = 5)
txt8.place(x=160, y=200)
# Sem 5
label7 = Label(root, text ="SEM 5").place(x=30, y=240)
txt9 = Text(root, height = 1, width = 5)
txt9.place(x=80, y=240)
txt10 = Text(root, height = 1, width = 5)
txt10.place(x=160, y=240)
# Sem 6
label8 = Label(root, text ="SEM 6").place(x=30, y=280)
txt11 = Text(root, height = 1, width = 5)
txt11.place(x=80, y=280)
txt12 = Text(root, height = 1, width = 5)
txt12.place(x=160, y=280)
# Sem 7
label9 = Label(root, text ="SEM 7").place(x=30, y=320)
txt13 = Text(root, height = 1, width = 5)
txt13.place(x=80, y=320)
txt14 = Text(root, height = 1, width = 5)
txt14.place(x=160, y=320)
# Sem 8
label10 = Label(root, text ="SEM 8").place(x=30, y=360)
txt15 = Text(root, height = 1, width = 5)
txt15.place(x=80, y=360)
txt16 = Text(root, height = 1, width = 5)
txt16.place(x=160, y=360)
#setting the button with calculate command:
button2 = Button(root, text ="Calculate" , command = calculate).place(x=100, y=400)
label11 =Label(root, text="")
label11.place(x=100, y=440)
#setting all creddits and gpas as zero by default:
txt1.insert(1.0, "0")
txt2.insert(1.0, "0")
txt3.insert(1.0, "0")
txt4.insert(1.0, "0")
txt5.insert(1.0, "0")
txt6.insert(1.0, "0")
txt7.insert(1.0, "0")
txt8.insert(1.0, "0")
txt9.insert(1.0, "0")
txt10.insert(1.0, "0")
txt11.insert(1.0, "0")
txt12.insert(1.0, "0")
txt13.insert(1.0, "0")
txt14.insert(1.0, "0")
txt15.insert(1.0, "0")
txt16.insert(1.0, "0")
# calling mainloop method which is used
# when the application is ready to run
# and it tells the code to keep displaying
root.mainloop()