1+ import tkinter as tk
2+ from tkinter import ttk
3+
4+
5+ root = tk .Tk () # Declare the root object
6+
7+ def process ():
8+ output = ['' for _ in range (10 )]
9+ count = 0
10+ num_subjects = 0
11+ total_mark = 0
12+ for element in entries .subjects :
13+ output [count ] = float (entries .subjects [element ].get ())
14+ if output [count ] != - 1.0 :
15+ num_subjects += 1
16+ total_mark += output [count ]
17+ count += 1
18+ agregate = 0
19+ if num_subjects != 0 :
20+ agregate = (total_mark / (100 * num_subjects )) * 100
21+
22+ print (output )
23+ print (agregate )
24+ aggregate_marks ['entry' ].delete (0 , 'end' )
25+ aggregate_marks ['entry' ].insert (0 , agregate )
26+
27+
28+ root .title ('Marks aggregator v1.0' ) # makes the title of the window
29+ Window_Title = ttk .Label (root , text = 'Marks aggregator' ) # Main heading of the window
30+
31+ class entries : # class containng entries for subjects where use inputs data
32+ subjects = {
33+ 'english' : ttk .Entry (root ),
34+ 'dhivehi' : ttk .Entry (root ),
35+ 'mathematics' : ttk .Entry (root ),
36+ 'chemistry' : ttk .Entry (root ),
37+ 'physics' : ttk .Entry (root ),
38+ 'biology' : ttk .Entry (root ),
39+ 'marine science' : ttk .Entry (root ),
40+ 'business' : ttk .Entry (root ),
41+ 'accounting' : ttk .Entry (root ),
42+ 'economics' : ttk .Entry (root )
43+ }
44+
45+ class labels : # Class contaning labels for subjects
46+ subjects = {
47+ 'english' : ttk .Label (root , text = 'English' ),
48+ 'dhivehi' : ttk .Label (root , text = 'Dhivehi' ),
49+ 'mathematics' : ttk .Label (root , text = 'Mathematics' ),
50+ 'chemistry' : ttk .Label (root , text = 'Chemistry' ),
51+ 'physics' : ttk .Label (root , text = 'Physics' ),
52+ 'biology' : ttk .Label (root , text = 'Biology' ),
53+ 'marine science' : ttk .Label (root , text = 'Marine Science' ),
54+ 'business' : ttk .Label (root , text = 'Business' ),
55+ 'accounting' : ttk .Label (root , text = 'Accounting' ),
56+ 'economics' : ttk .Label (root , text = 'Economics' )
57+ }
58+
59+ aggregate_marks = { # Dictionary containing users agregate marks and its label
60+ 'label' : ttk .Label (root , text = 'Aggregated Mark' ),
61+ 'entry' : ttk .Entry (root )
62+ }
63+
64+ #aggregate_marks['entry'].config(state='readonly') # Sets aggregatemarks to read only
65+ aggregate_marks ['entry' ].insert (0 , '0' ) # Sets agregate marks entry value to 0
66+
67+ # sets the positions and arrangement of the entries, and labels
68+ row_count = 1
69+ for element in labels .subjects :
70+ entries .subjects [element ].insert (0 , '-1' )
71+ entries .subjects [element ].grid (row = row_count , column = 1 , padx = 10 , pady = 5 )
72+ labels .subjects [element ].grid (row = row_count , column = 0 , padx = 10 , pady = 5 )
73+ row_count += 1
74+ column_count = 0
75+ for element in aggregate_marks :
76+ aggregate_marks [element ].grid (row = row_count + 1 , column = column_count , padx = 10 , pady = 5 )
77+ column_count += 1
78+ Window_Title .grid (row = 0 , column = 0 , columnspan = 2 )
79+
80+ # sets up the one button
81+ calculate = ttk .Button (root , text = 'Calculate' , command = process )
82+ calculate .grid (row = row_count , column = 0 , columnspan = 2 , padx = 5 , pady = 10 )
83+ root .mainloop ()
0 commit comments