-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
158 lines (131 loc) · 6.03 KB
/
main.py
File metadata and controls
158 lines (131 loc) · 6.03 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import tkinter as tk
from tkinter import ttk
root = tk.Tk() # Declare the root object
def process():
"""
Purpose
--------
To handle what pressing the button to process does.
Retreves all the enterd marks of the user, and outputs them in the aggregate mark entry
Variables
----------
count - a counter variable
num_subjects - counter for the number of subjects data is input for
total_mark - used for totaling the mark of the user, to help with calculating aggregate marks
agregate - holds the average marks of the user
Lists
------
output - list storing marks of the user per subject
Global vars used
-----------------
aggregate_marks - a dictionary which is the aggregate_marks entry showing the answer of the calculation to the user
entries.subjects = the dictionary that has the entries that user inputs their mark to
"""
# Initialising Lists
retrived_marks = [0 for _ in range(10)]
# Initialising Variables
subject_no = 0
number_subjects_processed = 0
total_of_all_marks = 0
aggregate_marks_calculation = 0
# Loop to retreve, store and total users marks and find the number of subjects user takes
for element in entries.subjects:
result = entries.subjects[element].get()
if result != '':
retrived_marks[subject_no] = float(result)
number_subjects_processed += 1
total_of_all_marks += retrived_marks[subject_no]
subject_no += 1
# Checks if the user did input data fr any subject and finds aggregate marks, avoids ZeroDivisionError, Outputs as a percentage of 100
if number_subjects_processed != 0:
aggregate_marks_calculation = (total_of_all_marks / (100 * number_subjects_processed)) * 100
# Print to console as debug logs
print(f'{number_subjects_processed}: subjects detected')
print(f'Users retreved marks are: {retrived_marks}')
print(f'Users aggregate marks (after calculation): {aggregate_marks_calculation}')
# Display marks in the aggregate marks entry
aggregate_marks['entry'].delete(0, 'end')
aggregate_marks['entry'].insert(0, aggregate_marks_calculation)
def setup():
"""
Purpose
-------
Moves the old setup code to setup the window from the mainloop to its own dedicated function
increases the modularity of the program
Variables used
--------------
index : as a counter variable
in the for loops to setup the structure of the program
element: holds the index of the dictionaries, NOTE Better name is needed
Global variables accesed
------------------------
aggregate_marks dictionary
used to make the structure of the aggregate marks display label and entry
class entry
dictionary subjects
stores the wigets of the entries of the users subjects
class labels
dictioary subjects
stores the corrosponding labels of the users subjects for the entries
process_button
used to store wiget of the button that is to be pressed to trigger procedure process to process and display users aggregate marks
heading
used to display the main header label of the window. also known as title
"""
# Declaring global variables
global process_button
global heading
for index, element in enumerate(labels.subjects, 1):
entries.subjects[element].insert(0, '') # Inserts -1 to every entry as starter
# Sets up the entries and labels
entries.subjects[element].grid(row=index, column=1, padx=10, pady=5)
labels.subjects[element].grid(row=index, column=0, padx=10, pady=5)
# Increments counter
index += 1
for index, element in enumerate(aggregate_marks, 0):
# Sets the position of the aggregate marks display label and button
aggregate_marks[element].grid(row=12, column=index, padx=10, pady=5)
# increments the counter
index += 1
# Sets up the locaton of the main heading of the indow
heading.grid(row=0, column=0, columnspan=2)
# sets up the one button (button to process the function)
process_button = ttk.Button(root, text='Process', command=process)
process_button.grid(row=11, column=0, columnspan=2, padx=5, pady=10)
root.title('Marks aggregator v1.0') # makes the title of the window
heading = ttk.Label(root, text='Marks aggregator') # Main heading of the window
class entries: # class containng entries for subjects where use inputs data
subjects = {
'english' : ttk.Entry(root),
'dhivehi' : ttk.Entry(root),
'mathematics' : ttk.Entry(root),
'chemistry' : ttk.Entry(root),
'physics' : ttk.Entry(root),
'biology' : ttk.Entry(root),
'marine science' : ttk.Entry(root),
'business' : ttk.Entry(root),
'accounting' : ttk.Entry(root),
'economics' : ttk.Entry(root)
}
class labels: # Class contaning labels for subjects
subjects = {
'english' : ttk.Label(root, text='English'),
'dhivehi' : ttk.Label(root, text='Dhivehi'),
'mathematics' : ttk.Label(root, text='Mathematics'),
'chemistry' : ttk.Label(root, text='Chemistry'),
'physics' : ttk.Label(root, text='Physics'),
'biology' : ttk.Label(root, text='Biology'),
'marine science' : ttk.Label(root, text='Marine Science'),
'business' : ttk.Label(root, text='Business'),
'accounting' : ttk.Label(root, text='Accounting'),
'economics' : ttk.Label(root, text='Economics')
}
aggregate_marks = { # Dictionary containing users agregate marks and its label
'label' : ttk.Label(root, text='Aggregated Mark'),
'entry' : ttk.Entry(root)
}
#aggregate_marks['entry'].config(state='readonly') # Sets aggregatemarks to read only
aggregate_marks['entry'].insert(0, '0') # Sets agregate marks entry value to 0
setup() # Procedure to go set everything in the program up for the user to be able to use
root.mainloop()
# Fixes are needed