-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrok_catogory.py
262 lines (153 loc) · 7.76 KB
/
wrok_catogory.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
from tkinter import *
from tkinter import ttk
import datetime
import test3
import work_database
date_and_time = datetime.date.today()
date1 = str(date_and_time)
def work(x, lbl):
global my_tree3
label1 = lbl(x, text="Expense Record Book")
label1.grid(column=0, row=0)
# add some style
style = ttk.Style()
# pick a theme
style.theme_use('default')
# configure the treeview colors
style.configure("Treeview", background="black", foreground="white", rowheight=25, fieldbackground="grey")
# change selected color
style.map("Treeview", background=[('selected', "green")])
# create a treeview
tree_frame3 = Frame(x)
tree_frame3.grid(padx=10, pady=10, row=1, column=0, rowspan=11)
# create scroll bar
tree_scroll4 = Scrollbar(tree_frame3)
tree_scroll4.pack(side=RIGHT, fill=Y)
# create the treeview
my_tree3 = ttk.Treeview(tree_frame3, yscrollcommand=tree_scroll4.set, selectmode="extended")
my_tree3.pack()
# configure the scroll bar
tree_scroll4.config(command=my_tree3.yview)
# define our columns
my_tree3['columns'] = ("id", "work_name", "discription")
# format our columns
my_tree3.column("#0", width=0, stretch=NO)
my_tree3.column("id", anchor=CENTER, width=50)
my_tree3.column("work_name", anchor=W, width=140)
my_tree3.column("discription", anchor=W, width=350)
# create Headings
my_tree3.heading("#0", text="", anchor=W)
my_tree3.heading("id", text="ID", anchor=CENTER)
my_tree3.heading("work_name", text="Work Name", anchor=W)
my_tree3.heading("discription", text="Discription", anchor=W)
# create striped row tags
my_tree3.tag_configure('oddrow', background="white", foreground="darkgreen")
my_tree3.tag_configure('evenrow', background="white", foreground="darkblue")
def work1(lbl, ent, btn, b):
date_label = lbl(b,
text="Execute Above Mentioned Details Here ------------>",
text_font=("Roboto Medium", -16)) # font name and size in px
date_label.grid(row=7, column=0,)
name_entry2 = ent(b,
width=10,
placeholder_text="Work Name")
name_entry2.grid(row=3, column=0, columnspan=1, pady=0, padx=20, sticky="we")
address_entry2 = ent(b,
width=10,
placeholder_text="Discription")
address_entry2.grid(row=4, column=0, columnspan=4, pady=0, padx=20, sticky="we")
# functions
work_database.dbconnectexp()
class work_handling:
def select_record(self, e):
# clear box
name_entry2.delete(0, END)
address_entry2.delete(0, END)
# Grab record number
selected = my_tree3.focus()
values = my_tree3.item(selected, "values")
#output entrybox
try:
name_entry2.insert(0, values[1])
address_entry2.insert(0, values[2])
except:
print("error detected")
#output listbox
# mylb.insert(1, values[2])
# mylb.insert(2, values[3])
def clearentrybox(self):
# clear box
name_entry2.delete(0, END)
address_entry2.delete(0, END)
def entering(self):
# try:
work_database.dbentryexp(name_entry2.get(), address_entry2.get())
my_tree3.delete(*my_tree3.get_children())
record4.fetching()
name_entry2.delete(0, END)
address_entry2.delete(0, END)
# except:
# mylb.insert(0, "Boxes Cannot be Blank")
def deleting(self):
selected = my_tree3.focus()
values = my_tree3.item(selected, "values")
work_database.dbdeleteexp(values[0])
my_tree3.delete(*my_tree3.get_children())
record4.fetching()
name_entry2.delete(0, END)
address_entry2.delete(0, END)
def updating(self):
selected = my_tree3.focus()
values = my_tree3.item(selected, "values")
try:
work_database.dbupdatexp(name_entry2.get(), address_entry2.get(), values[0])
except:
print("Error detected")
my_tree3.delete(*my_tree3.get_children())
record4.fetching()
name_entry2.delete(0, END)
address_entry2.delete(0, END)
def fetching(self):
data = work_database.dbfetchexp()
count = 0
try:
for i in data:
if count % 2 == 0:
my_tree3.insert(parent="", index="end", iid=count, text="", values=(i[0], i[1], i[2]), tags=("evenrow",))
else:
my_tree3.insert(parent="", index="end", iid=count, text="", values=(i[0], i[1], i[2]), tags=("oddrow",))
# increment counter
count += 1
except:
print("error detected")
record4 = work_handling()
# bind
my_tree3.bind("<ButtonRelease-1>", record4.select_record)
# buttons
add_button2 = btn(b,
text="Add",
border_width=2, # <- custom border_width
fg_color=None, # <- no fg_color
command=record4.entering)
add_button2.grid(row=7, column=2, padx=10)
del_button2 = btn(b,
text="Remove",
border_width=2, # <- custom border_width
fg_color=None, # <- no fg_color
command=record4.deleting)
del_button2.grid(row=7, column=3, padx=10)
update_button2 = btn(b,
text="Update",
border_width=2, # <- custom border_width
fg_color=None, # <- no fg_color
command=record4.updating)
update_button2.grid(row=7, column=4, padx=10)
# show_button = Button(data_frame, text="Show", width=10, command=record1.fetching)
# show_button.grid(row=5, column=5, padx=10)
record4.fetching()
clear_button2 = btn(b,
text="Clear Boxes",
border_width=2, # <- custom border_width
fg_color=None, # <- no fg_color
command=record4.clearentrybox)
clear_button2.grid(row=7, column=5, padx=10)