-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
325 lines (250 loc) · 12 KB
/
Copy pathmain.py
File metadata and controls
325 lines (250 loc) · 12 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
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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
import tkinter as tk
from tkinter import ttk
# * set up of the root window
root = tk.Tk()
root.geometry("600x500")
root.title("user interface database")
import conDB
conDB.initialiseConnection()
from tools import *
# this creates the database and the tables
setUpDatabase()
# * creation of the different tabs of the window
rootTab = ttk.Notebook(root)
tab1 = ttk.Frame(rootTab)
rootTab.add(tab1, text="info")
tab2 = ttk.Frame(rootTab)
rootTab.add(tab2, text="add data")
tab3 = ttk.Frame(rootTab)
rootTab.add(tab3, text="retrieve data")
tab4 = ttk.Frame(rootTab)
rootTab.add(tab4, text="remove data")
rootTab.pack(fill="both")
# * set up of the first tab
titleLabel = tk.Label(tab1, text="Information about the program", font="bold")
titleLabel.pack()
frameTextIntro = tk.Frame(tab1)
frameTextIntro.pack(fill="x")
textLabel = tk.Label(frameTextIntro,
text="This program was created in order to ease the interaction with the database.\n"+
"You can use it in order to add data to the database, retrive data from the database and also to remove\n" +
"data is you made a mistake somewhere. Here is an explanation of each tab:\n\n" +
"The tab 'add data' helps you add rows to the database.\n" +
"You can enter new donors (as long as they don't exist already) and also new donations.\n" +
"Donations can be saved from a donor but can also be anonymous.\n\n" +
"The tab 'retrieve data' will help you find data inside the database.\n" +
"You have different options to choose from: getting all the donors, getting all the donations,\n" +
"getting all the anonymous donations, getting the last 10 donations and lastly finding everything \n" +
"connected with a certain donor based on its first name and last name.\n\n" +
"The last tab called 'remove data' is to remove rows form the database.\n" +
"Again, you can remove donors and donations. If you remove a donor that has made donations, then \n" +
"Its donations will become anonymous.\n\n" +
"This program works by connecting to a MySQL server. Please install and start a server on your machine.",
justify="left")
textLabel.pack(side="left")
# * set up of the second tab
titleLabel = tk.Label(tab2, text="Enter new data into database", font="bold")
titleLabel.pack()
# ----- for adding a donor -----
frameSubtitle1 = tk.Frame(tab2)
frameSubtitle1.pack(fill="x")
subtitle1 = tk.Label(frameSubtitle1, text="Add a new donor here:")
subtitle1.pack(side="left")
# first name
frameFirstname = tk.Frame(tab2)
frameFirstname.pack(fill="x")
firstnameLabel = tk.Label(frameFirstname, text="first name:", width=20)
firstnameLabel.pack(side="left")
firstnameEntry = tk.Entry(frameFirstname)
firstnameEntry.pack(fill="x")
# last name
frameLastname = tk.Frame(tab2)
frameLastname.pack(fill="x")
lastnameLabel = tk.Label(frameLastname, text="last name:", width=20)
lastnameLabel.pack(side="left")
lastnameEntry = tk.Entry(frameLastname)
lastnameEntry.pack(fill="x")
# professoin
frameProfession = tk.Frame(tab2)
frameProfession.pack(fill="x")
professionLabel = tk.Label(frameProfession, text="profession: (not required)", width=20)
professionLabel.pack(side="left")
professionEntry = tk.Entry(frameProfession)
professionEntry.pack(fill="x")
# country
frameCountry = tk.Frame(tab2)
frameCountry.pack(fill="x")
countryLabel = tk.Label(frameCountry, text="country: (not required)", width=20)
countryLabel.pack(side="left")
countryEntry = tk.Entry(frameCountry)
countryEntry.pack(fill="x")
# this is the text that gives info about the process of the submission to the database
sideText1 = tk.StringVar()
sideText1.set("")
sideText1Label = tk.Label(tab2, textvariable=sideText1)
# button that submits info from the entry text boxes to the database
buttonSubmitDonor = tk.Button(tab2, text="submit info into database", command=lambda:submitInfoDonor(firstnameEntry, lastnameEntry, professionEntry, countryEntry, sideText1))
buttonSubmitDonor.pack(fill="x")
sideText1Label.pack()
# ----- for adding a donation -----
frameSubtitle2 = tk.Frame(tab2)
frameSubtitle2.pack(fill="x")
subtitle2Label = tk.Label(frameSubtitle2, text="Add a new donation here:")
subtitle2Label.pack(side="left")
# amount of money for donation
frameAmount = tk.Frame(tab2)
frameAmount.pack(fill="x")
amountLabel = tk.Label(frameAmount, text="amount in pounds:", width=20)
amountLabel.pack(side="left")
amountEntry = tk.Entry(frameAmount)
amountEntry.pack(fill="x")
# type of donation
frameTypeDonation = tk.Frame(tab2)
frameTypeDonation.pack(fill="x")
typeDonationLabel = tk.Label(frameTypeDonation, text="type of donation:", width=20)
typeDonationLabel.pack(side="left")
typeDonationEntry = tk.Entry(frameTypeDonation)
typeDonationEntry.pack(fill="x")
# donor first name
frameDonorFirstName = tk.Frame(tab2)
donorFirstNameLabel = tk.Label(frameDonorFirstName, text="donor first name:", width=20)
donorFirstNameLabel.pack(side="left")
donorFirstNameEntry = tk.Entry(frameDonorFirstName)
donorFirstNameEntry.pack(fill="x")
# donor last name
frameDonorLastName = tk.Frame(tab2)
donorLastNameLabel = tk.Label(frameDonorLastName, text="donor last name:", width=20)
donorLastNameLabel.pack(side="left")
donorLastNameEntry = tk.Entry(frameDonorLastName)
donorLastNameEntry.pack(fill="x")
# for the type of donor, if he is anonymous
frameAnonymous = tk.Frame(tab2)
frameAnonymous.pack(fill="x")
anonymousVar = tk.IntVar()
anonymousCheckBox = tk.Checkbutton(frameAnonymous, text="Anonymous donation ", variable=anonymousVar, onvalue=1, offvalue=0, command=lambda:switchAnonymousDonor(anonymousVar, donorFirstNameEntry, donorLastNameEntry))
anonymousCheckBox.pack(side="left")
# so that thigs are in the right order
frameDonorFirstName.pack(fill="x")
frameDonorLastName.pack(fill="x")
# this is the text that gives info about the process of the transaction
sideText2 = tk.StringVar()
sideText2.set("")
sideText2Label = tk.Label(tab2, textvariable=sideText2)
# button that submits info from the entry text boxes to the database
buttonSubmitDonation = tk.Button(tab2, text="submit info into database", command=lambda:submitInfoDonation(anonymousVar, amountEntry, typeDonationEntry, donorFirstNameEntry, donorLastNameEntry, sideText2))
buttonSubmitDonation.pack(fill="x")
sideText2Label.pack()
# * set up of the third tab
titleLabel = tk.Label(tab3, text="Retreive data from database", font="bold")
titleLabel.pack()
frameButtons1 = tk.Frame(tab3)
frameButtons1.pack(fill="x")
frameButtons2 = tk.Frame(tab3)
frameButtons2.pack(fill="x")
frameOutputInfo = tk.Frame(tab3)
frameOutputInfo.pack(fill="both")
outputInfo = tk.Text(frameOutputInfo)
outputInfo.pack(fill="both")
getAllInfoDonorButton = tk.Button(frameButtons1, text="get all info from donors", command=lambda:getAllInfoDonors(outputInfo))
getAllInfoDonorButton.pack(side="left")
getAllInfoDonationsButton = tk.Button(frameButtons1, text="get all info about donations", command=lambda:getAllDonations(outputInfo))
getAllInfoDonationsButton.pack(side="left")
getAllAnonymousDonationsButton = tk.Button(frameButtons1, text="get all anonymous donations", command=lambda:getAllAnonymousDonations(outputInfo))
getAllAnonymousDonationsButton.pack(side="left")
getAllAnonymousDonationsButton = tk.Button(frameButtons1, text="get last 10 donations", command=lambda:getLast10Donations(outputInfo))
getAllAnonymousDonationsButton.pack(side="left")
# for finding info about one donor
frameFirstName = tk.Frame(frameButtons2)
frameFirstName.pack(fill="x", side="left")
firstNameLabel = tk.Label(frameFirstName, text="first name donor:", width=15)
firstNameLabel.pack(side="left")
firstNameEntry = tk.Entry(frameFirstName)
firstNameEntry.pack(side="left")
frameLastName = tk.Frame(frameButtons2)
frameLastName.pack(side="left")
lastNameLabel = tk.Label(frameLastName, text="last name donor:", width=15)
lastNameLabel.pack(side="left")
lastNameEntry = tk.Entry(frameLastName)
lastNameEntry.pack(side="left")
searchButton = tk.Button(frameButtons2, text="search", command=lambda:searchCustomDonor(firstNameEntry, lastNameEntry, outputInfo))
searchButton.pack(side="left")
# * set up of the fourth tab
titleLabel = tk.Label(tab4, text="Remove data from the database", font="bold")
titleLabel.pack()
# ----- for removing a donor -----
frameSubtitle1 = tk.Frame(tab4)
frameSubtitle1.pack(fill="x")
subtitle1 = tk.Label(frameSubtitle1, text="Remove a donor here:")
subtitle1.pack(side="left")
# first name
frameFirstname = tk.Frame(tab4)
frameFirstname.pack(fill="x")
firstnameLabel = tk.Label(frameFirstname, text="first name:", width=20)
firstnameLabel.pack(side="left")
firstnameEntryRemove = tk.Entry(frameFirstname)
firstnameEntryRemove.pack(fill="x")
# last name
frameLastname = tk.Frame(tab4)
frameLastname.pack(fill="x")
lastnameLabel = tk.Label(frameLastname, text="last name:", width=20)
lastnameLabel.pack(side="left")
lastnameEntryRemove = tk.Entry(frameLastname)
lastnameEntryRemove.pack(fill="x")
# this is the text that gives info about the process of the submission to the database
sideText1Remove = tk.StringVar()
sideText1Remove.set("")
sideText1RemoveLabel = tk.Label(tab4, textvariable=sideText1Remove)
# button that submits info from the entry text boxes to the database
buttonSubmitDonor = tk.Button(tab4, text="remove from database", command=lambda:removeDonor(firstnameEntryRemove, lastnameEntryRemove, sideText1Remove))
buttonSubmitDonor.pack(fill="x")
sideText1RemoveLabel.pack()
# ----- for removing a donation -----
frameSubtitle2 = tk.Frame(tab4)
frameSubtitle2.pack(fill="x")
subtitle2Label = tk.Label(frameSubtitle2, text="Remove a donation here:")
subtitle2Label.pack(side="left")
# amount of money for donation
frameAmount = tk.Frame(tab4)
frameAmount.pack(fill="x")
amountLabel = tk.Label(frameAmount, text="amount:", width=20)
amountLabel.pack(side="left")
amountEntryRemove = tk.Entry(frameAmount)
amountEntryRemove.pack(fill="x")
# type of donation
frameTypeDonation = tk.Frame(tab4)
frameTypeDonation.pack(fill="x")
typeDonationLabel = tk.Label(frameTypeDonation, text="type of donation:", width=20)
typeDonationLabel.pack(side="left")
typeDonationEntryRemove = tk.Entry(frameTypeDonation)
typeDonationEntryRemove.pack(fill="x")
# donor first name
frameDonorFirstName = tk.Frame(tab4)
donorFirstNameLabel = tk.Label(frameDonorFirstName, text="donor first name:", width=20)
donorFirstNameLabel.pack(side="left")
donorfirstnameEntryRemove = tk.Entry(frameDonorFirstName)
donorfirstnameEntryRemove.pack(fill="x")
# donor last name
frameDonorLastName = tk.Frame(tab4)
donorLastNameLabel = tk.Label(frameDonorLastName, text="donor last name:", width=20)
donorLastNameLabel.pack(side="left")
donorLastNameEntryRemove = tk.Entry(frameDonorLastName)
donorLastNameEntryRemove.pack(fill="x")
# for the type of donor, if he is anonymous
frameAnonymous = tk.Frame(tab4)
frameAnonymous.pack(fill="x")
anonymousVarRermove = tk.IntVar()
anonymousCheckBoxRemove = tk.Checkbutton(frameAnonymous, text="Anonymous donation ", variable=anonymousVarRermove, onvalue=1, offvalue=0, command=lambda:switchAnonymousDonorRemove(anonymousVarRermove, donorfirstnameEntryRemove, donorLastNameEntryRemove))
anonymousCheckBoxRemove.pack(side="left")
# so that things are in the right order
frameDonorFirstName.pack(fill="x")
frameDonorLastName.pack(fill="x")
# this is the text that gives info about the process of the transaction
sideText2Remove = tk.StringVar()
sideText2Remove.set("")
sideText2RemoveLabel = tk.Label(tab4, textvariable=sideText2Remove)
# button that submits info from the entry text boxes to the database
buttonSubmitDonation = tk.Button(tab4, text="remove from database", command=lambda:removeDonation(anonymousVarRermove, amountEntryRemove, typeDonationEntryRemove, donorfirstnameEntryRemove, donorLastNameEntryRemove, sideText2Remove))
buttonSubmitDonation.pack(fill="x")
sideText2RemoveLabel.pack()
# * opens the root
root.mainloop()