-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_2.py
More file actions
146 lines (113 loc) · 4.34 KB
/
example_2.py
File metadata and controls
146 lines (113 loc) · 4.34 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
import ttkbootstrap as ttk
from ttkbootstrap.constants import *
from ttkbootstrap.toast import ToastNotification
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.validation import add_regex_validation
class Gradebook(ttk.Frame):
def __init__(self, master_window):
super().__init__(master_window, padding=(20,10))
self.pack(fill=BOTH, expand=YES)
self.name = ttk.StringVar(value="")
self.student_id = ttk.StringVar(value="")
self.course_name = ttk.StringVar(value="")
self.final_score = ttk.DoubleVar(value=0)
self.data = []
self.colors = master_window.style.colors
instruction_text = "Please enter your contact information: "
instruction = ttk.Label(self, text=instruction_text, width=50)
instruction.pack(fill=X, pady=10)
self.create_form_entry("Name: ", self.name)
self.create_form_entry("Student ID: ", self.student_id)
self.create_form_entry("Course Name: ", self.course_name)
self.final_score_input = self.create_form_entry("Final Score: ", self.final_score)
self.create_meter()
self.create_buttonbox()
self.table = self.create_table()
def create_form_entry(self, label, variable):
form_field_container = ttk.Frame(self)
form_field_container.pack(fill=X, expand=YES, pady=5)
form_field_label = ttk.Label(master=form_field_container, text=label, width=15)
form_field_label.pack(side=LEFT, padx=12)
form_input = ttk.Entry(master=form_field_container, textvariable=variable)
form_input.pack(side=LEFT, padx=5, fill=X, expand=YES)
add_regex_validation(form_input, r'^[a-zA-Z0-9_]*$')
return form_input
def create_buttonbox(self):
button_container = ttk.Frame(self)
button_container.pack(fill=X, expand=YES, pady=(15, 10))
cancel_btn = ttk.Button(
master=button_container,
text="Cancel",
command=self.on_cancel,
bootstyle=DANGER,
width=6,
)
cancel_btn.pack(side=RIGHT, padx=5)
submit_btn = ttk.Button(
master=button_container,
text="Submit",
command=self.on_submit,
bootstyle=SUCCESS,
width=6,
)
submit_btn.pack(side=RIGHT, padx=5)
def create_meter(self):
meter = ttk.Meter(
master=self,
metersize=150,
padding=5,
amounttotal=100,
amountused=50,
metertype="full",
subtext="Final Score",
interactive=True,
)
meter.pack()
self.final_score.set(meter.amountusedvar)
self.final_score_input.configure(textvariable=meter.amountusedvar)
def create_table(self):
coldata = [
{"text": "Name"},
{"text": "Student ID", "stretch": False},
{"text": "Course Name"},
{"text": "Final Score", "stretch": False}
]
print(self.data)
table = Tableview(
master=self,
coldata=coldata,
rowdata=self.data,
paginated=True,
searchable=True,
bootstyle=PRIMARY,
stripecolor=(self.colors.light, None),
)
table.pack(fill=BOTH, expand=YES, padx=10, pady=10)
return table
def on_submit(self):
"""Print the contents to console and return the values."""
name = self.name.get()
student_id = self.student_id.get()
course_name = self.course_name.get()
final_score = self.final_score.get()
print("Name:", name)
print("Student ID: ", student_id)
print("Course Name:", course_name)
print("Final Score:", final_score)
toast = ToastNotification(
title="Submission successful!",
message="Your data has been successfully submitted.",
duration=3000,
)
toast.show_toast()
# Refresh table
self.data.append((name, student_id, course_name, final_score))
self.table.destroy()
self.table = self.create_table()
def on_cancel(self):
"""Cancel and close the application."""
self.quit()
if __name__ == "__main__":
app = ttk.Window("Gradebook", "superhero", resizable=(False, False))
Gradebook(app)
app.mainloop()