Guest User

Untitled

a guest
May 24th, 2018
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 83.49 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter.messagebox
  3. import sqlite3
  4. import calendar
  5. import datetime
  6. import time
  7.  
  8. db = sqlite3.connect('login.db')
  9. cursor = db.cursor()
  10. cursor.execute('''
  11. CREATE TABLE IF NOT EXISTS history(id INTEGER PRIMARY KEY, username TEXT, totalbudget FLOAT, totalusage FLOAT,
  12. highestcat TEXT, highestvalue FLOAT, lowestcat TEXT, lowestvalue FLOAT, foodbudget FLOAT, educationbudget FLOAT,
  13. groceriesbudget FLOAT, fuelbudget FLOAT, clothingbudget FLOAT,
  14. transportbudget FLOAT, utilitiesbudget FLOAT, healthbudget FLOAT,
  15. insurancebudget FLOAT, othersbudget FLOAT, food FLOAT, education FLOAT,
  16. groceries FLOAT, fuel FLOAT, clothing FLOAT, transport FLOAT,
  17. utilities FLOAT, health FLOAT, insurance FLOAT, others FLOAT, monthnumber INT)
  18. ''')
  19. db.commit()
  20.  
  21. cursor.execute('''
  22. CREATE TABLE IF NOT EXISTS users(id INTEGER PRIMARY KEY, username TEXT,
  23. password TEXT, foodbudget FLOAT, educationbudget FLOAT,
  24. groceriesbudget FLOAT, fuelbudget FLOAT, clothingbudget FLOAT,
  25. transportbudget FLOAT, utilitiesbudget FLOAT, healthbudget FLOAT,
  26. insurancebudget FLOAT, othersbudget FLOAT, food FLOAT, education FLOAT,
  27. groceries FLOAT, fuel FLOAT, clothing FLOAT, transport FLOAT,
  28. utilities FLOAT, health FLOAT, insurance FLOAT, others FLOAT,
  29. dateinitial TEXT, dateafteronemonth TEXT, datetoday TEXT, state INT, monthnumber INT,
  30. totalbudget FLOAT, totalusage FLOAT, highestcat TEXT, highestvalue FLOAT,
  31. lowestcat TEXT, lowestvalue FLOAT)
  32. ''')
  33. db.commit()
  34.  
  35. root = Tk()
  36. root.geometry("1000x750")
  37. root.title("Savely")
  38.  
  39. LoginFrame = Frame(root)
  40. LoginFrame.pack()
  41.  
  42. RegisterFrame = Frame(root)
  43.  
  44. MainInterfaceFrame = Frame(root)
  45.  
  46. ExpenditureInterface = Frame(root)
  47.  
  48. ProfileFrame = Frame(root)
  49.  
  50. BudgetingFrame = Frame(root)
  51.  
  52. SummaryFrame = Frame(root)
  53.  
  54. HistoryFrame = Frame(root)
  55.  
  56. def LoginRegisterClicked():
  57. LoginFrame.pack_forget()
  58. RegisterFrame.pack()
  59. entry_1.delete(0, END)
  60. entry_1.insert(0, "")
  61. entry_2.delete(0, END)
  62. entry_2.insert(0, "")
  63.  
  64. def RegisterClicked():
  65. global InfoInput_1
  66. global InfoInput_2
  67. global InfoInput_3
  68. GetRegistrationName = InfoInput_1.get()
  69. GetRegistrationPass = InfoInput_2.get()
  70. GetRegistrationConfirmPass = InfoInput_3.get()
  71.  
  72. checkTaken = 'No'
  73. for row in cursor.execute('SELECT username FROM users').fetchall():
  74. if row[0] == GetRegistrationName:
  75. checkTaken = 'Yes'
  76.  
  77. if len(GetRegistrationName) <= 1 or len(GetRegistrationPass) <= 1:
  78. tkinter.messagebox.showerror("Error", "Invalid Credentials Entered")
  79. elif GetRegistrationPass != GetRegistrationConfirmPass:
  80. tkinter.messagebox.showerror("Error", "Passwords do not match")
  81. elif GetRegistrationName == GetRegistrationPass:
  82. tkinter.messagebox.showerror("Error", "Password cannot be the same as the username for security purposes")
  83. elif checkTaken == 'Yes':
  84. tkinter.messagebox.showerror("Error", "That username has already been taken")
  85. else:
  86. cursor.execute(''' INSERT INTO users(username, password, foodbudget, educationbudget, groceriesbudget, fuelbudget,
  87. clothingbudget, transportbudget, utilitiesbudget, healthbudget, insurancebudget, othersbudget,
  88. food, education, groceries, fuel, clothing, transport, utilities, health,
  89. insurance, others, state, monthnumber,
  90. totalbudget, totalusage, highestcat, highestvalue, lowestcat, lowestvalue)
  91. VALUES(?, ?, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0) ''',
  92. (GetRegistrationName, GetRegistrationPass))
  93. db.commit()
  94. tkinter.messagebox.showinfo("Success", "Registration Successful")
  95. InfoInput_1.delete(0, END)
  96. InfoInput_1.insert(0, "")
  97. InfoInput_2.delete(0, END)
  98. InfoInput_2.insert(0, "")
  99. InfoInput_3.delete(0, END)
  100. InfoInput_3.insert(0, "")
  101. RegisterFrame.pack_forget()
  102. LoginFrame.pack()
  103.  
  104. def fromRegToLogPage():
  105. RegisterFrame.pack_forget()
  106. LoginFrame.pack()
  107. InfoInput_1.delete(0, END)
  108. InfoInput_1.insert(0, "")
  109. InfoInput_2.delete(0, END)
  110. InfoInput_2.insert(0, "")
  111. InfoInput_3.delete(0, END)
  112. InfoInput_3.insert(0, "")
  113.  
  114. global state
  115. GetLoginName = ' '
  116.  
  117. def LoginCredentials():
  118. global entry_1
  119. global entry_2
  120. global GetLoginName
  121. global GetLoginPassword
  122. GetLoginName = entry_1.get()
  123. GetLoginPassword = entry_2.get()
  124. str(GetLoginName)
  125. str(GetLoginPassword)
  126. test = cursor.execute(''' SELECT password FROM users WHERE username = ?''', (GetLoginName, )).fetchone()
  127. if test:
  128. checkPassword = test
  129. if GetLoginPassword == checkPassword[0]:
  130. tkinter.messagebox.showinfo("Perfect", "Login Successful")
  131. global now
  132. now = datetime.datetime.today()
  133. test = cursor.execute(''' SELECT dateinitial FROM users WHERE username = ?''', (GetLoginName,)).fetchone()
  134.  
  135. cursor.execute(''' SELECT foodbudget, educationbudget, groceriesbudget, fuelbudget, clothingbudget, transportbudget,
  136. utilitiesbudget, healthbudget, insurancebudget, othersbudget FROM users WHERE username=?''',
  137. (GetLoginName,))
  138. budgetValues = cursor.fetchone()
  139.  
  140. cursor.execute(''' SELECT food, education, groceries, fuel, clothing, transport,
  141. utilities, health, insurance, others FROM users WHERE username=?''',
  142. (GetLoginName,))
  143. usageValues = cursor.fetchone()
  144.  
  145. TotalBudget = 0
  146. for values in budgetValues:
  147. TotalBudget = TotalBudget + values
  148.  
  149. TotalUsage = 0
  150. highestUsage = 0
  151. lowestUsage = 99999999
  152. highestUsageCat = 'Nil'
  153. lowestUsageCat = 'Nil'
  154. counter = 0
  155. overBudget = 0
  156. overBudgetCat = []
  157. i = 0
  158. categoryList = ['Food', 'Education', 'Groceries', 'Fuel', 'Clothing', 'Transport', 'Utilities', 'Health', 'Insurance', 'Others']
  159. for values in usageValues:
  160. if values > budgetValues[i]:
  161. overBudgetCat.append(categoryList[i])
  162. overBudget = overBudget + 1
  163. i = i + 1
  164.  
  165. for values in usageValues:
  166. TotalUsage = TotalUsage + values
  167. if values > highestUsage:
  168. highestUsage = values
  169. if counter == 0:
  170. highestUsageCat = 'Food'
  171. elif counter == 1:
  172. highestUsageCat = 'Education'
  173. elif counter == 2:
  174. highestUsageCat = 'Groceries'
  175. elif counter == 3:
  176. highestUsageCat = 'Fuel'
  177. elif counter == 4:
  178. highestUsageCat = 'Clothing'
  179. elif counter == 5:
  180. highestUsageCat = 'Transport'
  181. elif counter == 6:
  182. highestUsageCat = 'Utilities'
  183. elif counter == 7:
  184. highestUsageCat = 'Health'
  185. elif counter == 8:
  186. highestUsageCat = 'Insurance'
  187. elif counter == 9:
  188. highestUsageCat = 'Others'
  189. counter = counter + 1
  190. counter = 0
  191. for values in usageValues:
  192. if values < lowestUsage and values != 0:
  193. lowestUsage = values
  194. if counter == 0:
  195. lowestUsageCat = 'Food'
  196. elif counter == 1:
  197. lowestUsageCat = 'Education'
  198. elif counter == 2:
  199. lowestUsageCat = 'Groceries'
  200. elif counter == 3:
  201. lowestUsageCat = 'Fuel'
  202. elif counter == 4:
  203. lowestUsageCat = 'Clothing'
  204. elif counter == 5:
  205. lowestUsageCat = 'Transport'
  206. elif counter == 6:
  207. lowestUsageCat = 'Utilities'
  208. elif counter == 7:
  209. lowestUsageCat = 'Health'
  210. elif counter == 8:
  211. lowestUsageCat = 'Insurance'
  212. elif counter == 9:
  213. lowestUsageCat = 'Others'
  214.  
  215. counter = counter + 1
  216.  
  217. cursor.execute(''' UPDATE users SET totalbudget = ?, totalusage = ?, highestcat = ?, highestvalue = ?,
  218. lowestcat = ?, lowestvalue = ? WHERE username = ?''', (TotalBudget, TotalUsage, highestUsageCat,
  219. highestUsage, lowestUsageCat,
  220. lowestUsage, GetLoginName,))
  221.  
  222. if test[0] is None:
  223. cursor.execute(''' UPDATE users SET dateinitial = ? WHERE username = ? ''', (now, GetLoginName,))
  224. db.commit()
  225. days = calendar.monthrange(now.year, now.month)[1]
  226. afterOneMonth = now + datetime.timedelta(days=days)
  227. cursor.execute(''' UPDATE users SET dateafteronemonth = ? WHERE username = ? ''',
  228. (afterOneMonth, GetLoginName,))
  229. db.commit()
  230.  
  231. cursor.execute(''' UPDATE users SET datetoday = ? WHERE username = ? ''', (now, GetLoginName,))
  232. db.commit()
  233. global monthEndDate
  234. global today
  235. global daysLeft
  236. monthEndDate = cursor.execute(''' SELECT dateafteronemonth FROM users WHERE username = ?''',
  237. (GetLoginName,)).fetchone()
  238.  
  239. time.sleep(0.5)
  240. mainInterface()
  241. entry_1.delete(0, END)
  242. entry_1.insert(0, "")
  243. entry_2.delete(0, END)
  244. entry_2.insert(0, "")
  245.  
  246. test = cursor.execute(''' SELECT foodbudget, educationbudget, groceriesbudget, fuelbudget, clothingbudget, transportbudget,
  247. utilitiesbudget, healthbudget, insurancebudget, othersbudget FROM users WHERE username=?''', (GetLoginName,)).fetchone()
  248. total = 0
  249. for values in test:
  250. total = total + values
  251. if total == 0:
  252. tkinter.messagebox.showinfo("Welcome", "The system has detected that you are a new user. You will now be redirected to the budgeting page to insert your budget for each category")
  253. state = 1
  254. time.sleep(1)
  255. LoginFrame.pack_forget()
  256. MainInterfaceFrame.pack_forget()
  257. BudgetingFrame.pack()
  258.  
  259. now = datetime.datetime.today()
  260. daysLeft = (datetime.datetime.strptime(monthEndDate[0], '%Y-%m-%d %H:%M:%S.%f') - now).days
  261. if daysLeft <= 0:
  262.  
  263. foodBudgetHistory = cursor.execute(''' SELECT foodbudget FROM users where username = ? ''',
  264. (GetLoginName,)).fetchone()
  265. educationBudgetHistory = cursor.execute(''' SELECT educationbudget FROM users where username = ? ''',
  266. (GetLoginName,)).fetchone()
  267. groceriesBudgetHistory = cursor.execute(''' SELECT groceriesbudget FROM users where username = ? ''',
  268. (GetLoginName,)).fetchone()
  269. fuelBudgetHistory = cursor.execute(''' SELECT fuelbudget FROM users where username = ? ''',
  270. (GetLoginName,)).fetchone()
  271. clothingBudgetHistory = cursor.execute(''' SELECT clothingbudget FROM users where username = ? ''',
  272. (GetLoginName,)).fetchone()
  273. transportBudgetHistory = cursor.execute(''' SELECT transportbudget FROM users where username = ? ''',
  274. (GetLoginName,)).fetchone()
  275. utilitiesBudgetHistory = cursor.execute(''' SELECT utilitiesbudget FROM users where username = ? ''',
  276. (GetLoginName,)).fetchone()
  277. healthBudgetHistory = cursor.execute(''' SELECT healthbudget FROM users where username = ? ''',
  278. (GetLoginName,)).fetchone()
  279. insuranceBudgetHistory = cursor.execute(''' SELECT insurancebudget FROM users where username = ? ''',
  280. (GetLoginName,)).fetchone()
  281. othersBudgetHistory = cursor.execute(''' SELECT othersbudget FROM users where username = ? ''',
  282. (GetLoginName,)).fetchone()
  283.  
  284. foodHistory = cursor.execute(''' SELECT food FROM users where username = ? ''',
  285. (GetLoginName,)).fetchone()
  286. educationHistory = cursor.execute(''' SELECT education FROM users where username = ? ''',
  287. (GetLoginName,)).fetchone()
  288. groceriesHistory = cursor.execute(''' SELECT groceries FROM users where username = ? ''',
  289. (GetLoginName,)).fetchone()
  290. fuelHistory = cursor.execute(''' SELECT fuel FROM users where username = ? ''',
  291. (GetLoginName,)).fetchone()
  292. clothingHistory = cursor.execute(''' SELECT clothing FROM users where username = ? ''',
  293. (GetLoginName,)).fetchone()
  294. transportHistory = cursor.execute(''' SELECT transport FROM users where username = ? ''',
  295. (GetLoginName,)).fetchone()
  296. utilitiesHistory = cursor.execute(''' SELECT utilities FROM users where username = ? ''',
  297. (GetLoginName,)).fetchone()
  298. healthHistory = cursor.execute(''' SELECT health FROM users where username = ? ''',
  299. (GetLoginName,)).fetchone()
  300. insuranceHistory = cursor.execute(''' SELECT insurance FROM users where username = ? ''',
  301. (GetLoginName,)).fetchone()
  302. othersHistory = cursor.execute(''' SELECT others FROM users where username = ? ''',
  303. (GetLoginName,)).fetchone()
  304.  
  305. totalBudgetHistory = cursor.execute(''' SELECT totalbudget FROM users where username = ? ''',
  306. (GetLoginName,)).fetchone()
  307. totalUsageHistory = cursor.execute(''' SELECT totalusage FROM users where username = ? ''',
  308. (GetLoginName,)).fetchone()
  309. highestCatHistory = cursor.execute(''' SELECT highestcat FROM users where username = ? ''',
  310. (GetLoginName,)).fetchone()
  311. highestValueHistory = cursor.execute(''' SELECT highestvalue FROM users where username = ? ''',
  312. (GetLoginName,)).fetchone()
  313. lowestCatHistory = cursor.execute(''' SELECT lowestcat FROM users where username = ? ''',
  314. (GetLoginName,)).fetchone()
  315. lowestValueHistory = cursor.execute(''' SELECT lowestvalue FROM users where username = ? ''',
  316. (GetLoginName,)).fetchone()
  317.  
  318. monthnumber = cursor.execute(''' SELECT monthnumber FROM users WHERE username = ? ''',
  319. (GetLoginName,)).fetchone()
  320. updatedmonthnumber = int(monthnumber[0]) + 1
  321.  
  322. cursor.execute(''' UPDATE users SET monthnumber = ? ''', (updatedmonthnumber,))
  323. db.commit()
  324.  
  325. cursor.execute(''' INSERT INTO history (username, foodbudget, educationbudget, groceriesbudget,
  326. fuelbudget, clothingbudget, transportbudget, utilitiesbudget, healthbudget,
  327. insurancebudget, othersbudget, food, education, groceries, fuel, clothing,
  328. transport, utilities, health, insurance, others, monthnumber, totalbudget, totalusage,
  329. highestcat, highestvalue, lowestcat, lowestvalue ) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''',
  330. (GetLoginName, foodBudgetHistory[0], educationBudgetHistory[0], groceriesBudgetHistory[0],
  331. fuelBudgetHistory[0], clothingBudgetHistory[0], transportBudgetHistory[0],
  332. utilitiesBudgetHistory[0], healthBudgetHistory[0], insuranceBudgetHistory[0],
  333. othersBudgetHistory[0], foodHistory[0], educationHistory[0], groceriesHistory[0],
  334. fuelHistory[0], clothingHistory[0], transportHistory[0], utilitiesHistory[0],
  335. healthHistory[0], insuranceHistory[0], othersHistory[0], updatedmonthnumber,
  336. totalBudgetHistory[0], totalUsageHistory[0], highestCatHistory[0], highestValueHistory[0],
  337. lowestCatHistory[0], lowestValueHistory[0]))
  338. db.commit()
  339.  
  340.  
  341. cursor.execute(''' UPDATE users SET dateinitial = ? WHERE username = ? ''', (now, GetLoginName))
  342. db.commit()
  343. days = calendar.monthrange(now.year, now.month)[1]
  344. afterOneMonth = now + datetime.timedelta(days=days)
  345. cursor.execute(''' UPDATE users SET dateafteronemonth = ? WHERE username = ? ''',
  346. (afterOneMonth, GetLoginName))
  347. db.commit()
  348.  
  349.  
  350. cursor.execute(''' UPDATE users SET foodbudget = 0.0, educationbudget = 0.0, groceriesbudget = 0.0, fuelbudget = 0.0,
  351. clothingbudget = 0.0, transportbudget = 0.0, utilitiesbudget = 0.0, healthbudget = 0.0, insurancebudget = 0.0, othersbudget = 0.0,
  352. food = 0.0, education = 0.0, groceries = 0.0, fuel = 0.0, clothing = 0.0, transport = 0.0, utilities = 0.0, health = 0.0,
  353. insurance = 0.0, others = 0.0 WHERE username = ? ''', (GetLoginName, ))
  354. db.commit()
  355.  
  356. tkinter.messagebox.showinfo("Notification",
  357. "It's already been a month. You are now being redirected to the budgeting interface to enter your budget for this month")
  358. LoginFrame.pack_forget()
  359. MainInterfaceFrame.pack_forget()
  360. BudgetingFrame.pack()
  361.  
  362. cursor.execute(''' SELECT foodbudget, educationbudget, groceriesbudget, fuelbudget, clothingbudget, transportbudget,
  363. utilitiesbudget, healthbudget, insurancebudget, othersbudget FROM users WHERE username=?''',
  364. (GetLoginName,))
  365. budgetValues = cursor.fetchone()
  366.  
  367. cursor.execute(''' SELECT food, education, groceries, fuel, clothing, transport,
  368. utilities, health, insurance, others FROM users WHERE username=?''',
  369. (GetLoginName,))
  370. usageValues = cursor.fetchone()
  371.  
  372. TotalBudget = 0
  373. for values in budgetValues:
  374. TotalBudget = TotalBudget + values
  375.  
  376. TotalUsage = 0
  377. highestUsage = 0
  378. lowestUsage = 99999999
  379. highestUsageCat = 'Nil'
  380. lowestUsageCat = 'Nil'
  381. counter = 0
  382. overBudget = 0
  383. overBudgetCat = []
  384. i = 0
  385. categoryList = ['Food', 'Education', 'Groceries', 'Fuel', 'Clothing', 'Transport', 'Utilities', 'Health', 'Insurance', 'Others']
  386. for values in usageValues:
  387. if values > budgetValues[i]:
  388. overBudgetCat.append(categoryList[i])
  389. overBudget = overBudget + 1
  390. i = i + 1
  391.  
  392. for values in usageValues:
  393. TotalUsage = TotalUsage + values
  394. if values > highestUsage:
  395. highestUsage = values
  396. if counter == 0:
  397. highestUsageCat = 'Food'
  398. elif counter == 1:
  399. highestUsageCat = 'Education'
  400. elif counter == 2:
  401. highestUsageCat = 'Groceries'
  402. elif counter == 3:
  403. highestUsageCat = 'Fuel'
  404. elif counter == 4:
  405. highestUsageCat = 'Clothing'
  406. elif counter == 5:
  407. highestUsageCat = 'Transport'
  408. elif counter == 6:
  409. highestUsageCat = 'Utilities'
  410. elif counter == 7:
  411. highestUsageCat = 'Health'
  412. elif counter == 8:
  413. highestUsageCat = 'Insurance'
  414. elif counter == 9:
  415. highestUsageCat = 'Others'
  416. counter = counter + 1
  417. counter = 0
  418. for values in usageValues:
  419. if values < lowestUsage and values != 0:
  420. lowestUsage = values
  421. if counter == 0:
  422. lowestUsageCat = 'Food'
  423. elif counter == 1:
  424. lowestUsageCat = 'Education'
  425. elif counter == 2:
  426. lowestUsageCat = 'Groceries'
  427. elif counter == 3:
  428. lowestUsageCat = 'Fuel'
  429. elif counter == 4:
  430. lowestUsageCat = 'Clothing'
  431. elif counter == 5:
  432. lowestUsageCat = 'Transport'
  433. elif counter == 6:
  434. lowestUsageCat = 'Utilities'
  435. elif counter == 7:
  436. lowestUsageCat = 'Health'
  437. elif counter == 8:
  438. lowestUsageCat = 'Insurance'
  439. elif counter == 9:
  440. lowestUsageCat = 'Others'
  441.  
  442. counter = counter + 1
  443.  
  444. text = ''
  445. for x in overBudgetCat:
  446. text = text + x + '\n'
  447.  
  448. state = cursor.execute(''' SELECT state FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  449.  
  450. if state[0] == 1:
  451. if overBudget > 0:
  452. tkinter.messagebox.showwarning("Warning",
  453. "You have exceeded the budget limit for the following categories:" + "\n" + "\n" + text + "\n" + "\n" + "Be careful while spending in the above categories")
  454.  
  455. if TotalUsage > 0 and TotalBudget > 0:
  456. percentage = (float(TotalUsage) / float(TotalBudget)) * 100
  457. if percentage > 100:
  458. tkinter.messagebox.showwarning("Warning", "You have exceeded your total budget for this month")
  459. elif percentage >= 70:
  460. tkinter.messagebox.showwarning("Warning",
  461. "You have exceeded 70% of your budget for this month. Be careful with your spending")
  462. c.select()
  463. else:
  464. c.deselect()
  465.  
  466. else:
  467. tkinter.messagebox.showerror("Error", "Wrong Password")
  468. else:
  469. tkinter.messagebox.showerror("Error", "User does not exist. Please register first.")
  470.  
  471. def mainInterface():
  472. LoginFrame.pack_forget()
  473. MainInterfaceFrame.pack()
  474.  
  475. def onClickExpenditure():
  476. MainInterfaceFrame.pack_forget()
  477. ExpenditureInterface.pack()
  478.  
  479. def onClickProfile():
  480. MainInterfaceFrame.pack_forget()
  481. ProfileFrame.pack()
  482.  
  483. def onClickInsertValue():
  484. global variable
  485. global inputCategoryValue
  486. obtainedCategory = variable.get()
  487. obtainedCategoryValue = inputCategoryValue.get()
  488. cursor.execute(''' SELECT food, education, groceries, fuel, clothing, transport,
  489. utilities, health, insurance, others FROM users WHERE username=?''', (GetLoginName,))
  490. values = cursor.fetchone()
  491. global initialValue
  492. global newValue
  493. if obtainedCategoryValue:
  494. if str(obtainedCategoryValue).isdigit():
  495. if obtainedCategory == 'Food':
  496. initialValue = values[0]
  497. newValue = float(initialValue) + float(obtainedCategoryValue)
  498. cursor.execute(''' UPDATE users SET food = ? WHERE username = ? ''', (newValue, GetLoginName,))
  499. db.commit()
  500. testB = cursor.execute(''' SELECT foodbudget FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  501. testU = cursor.execute(''' SELECT food FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  502. if float(testB[0]) > 0.0:
  503. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  504. if ((float(testU[0]) / float(testB[0])) * 100)> 70:
  505. tkinter.messagebox.showwarning("Warning", "You surpassed 70 percent of your budget for Food. Be wise with your spendings.")
  506. else:
  507. tkinter.messagebox.showwarning("Warning", "You have exceeded the budget for Food. Be extra careful with your money.")
  508. else:
  509. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  510.  
  511. elif obtainedCategory == 'Education':
  512. initialValue = values[1]
  513. newValue = float(initialValue) + float(obtainedCategoryValue)
  514. cursor.execute(''' UPDATE users SET education = ? WHERE username = ? ''', (newValue, GetLoginName,))
  515. db.commit()
  516. testB = cursor.execute(''' SELECT educationbudget FROM users WHERE username = ? ''',
  517. (GetLoginName,)).fetchone()
  518. testU = cursor.execute(''' SELECT education FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  519. if float(testB[0]) > 0.0:
  520. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  521. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  522. tkinter.messagebox.showwarning("Warning", "You surpassed 70 percent of your budget for Education. Be wise with your spendings.")
  523. else:
  524. tkinter.messagebox.showwarning("Warning", "You have exceeded the budget for Education. Be extra careful with your money")
  525. else:
  526. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  527.  
  528. elif obtainedCategory == 'Groceries':
  529. initialValue = values[2]
  530. newValue = float(initialValue) + float(obtainedCategoryValue)
  531. cursor.execute(''' UPDATE users SET groceries = ? WHERE username = ? ''', (newValue, GetLoginName,))
  532. db.commit()
  533. testB = cursor.execute(''' SELECT groceriesbudget FROM users WHERE username = ? ''',
  534. (GetLoginName,)).fetchone()
  535. testU = cursor.execute(''' SELECT groceries FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  536. if float(testB[0]) > 0.0:
  537. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  538. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  539. tkinter.messagebox.showwarning("Warning",
  540. "You surpassed 70 percent of your budget for Groceries. Be wise with your spendings.")
  541. else:
  542. tkinter.messagebox.showwarning("Warning",
  543. "You have exceeded the budget for Groceries. Be extra careful with your money.")
  544. else:
  545. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  546.  
  547. elif obtainedCategory == 'Fuel':
  548. initialValue = values[3]
  549. newValue = float(initialValue) + float(obtainedCategoryValue)
  550. cursor.execute(''' UPDATE users SET fuel = ? WHERE username = ? ''', (newValue, GetLoginName,))
  551. db.commit()
  552. testB = cursor.execute(''' SELECT fuelbudget FROM users WHERE username = ? ''',
  553. (GetLoginName,)).fetchone()
  554. testU = cursor.execute(''' SELECT fuel FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  555. if float(testB[0]) > 0.0:
  556. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  557. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  558. tkinter.messagebox.showwarning("Warning",
  559. "You surpassed 70 percent of your budget for Fuel. Be wise with your spendings.")
  560. else:
  561. tkinter.messagebox.showwarning("Warning",
  562. "You have exceeded the budget for Fuel. Be extra careful with your money.")
  563. else:
  564. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  565.  
  566. elif obtainedCategory == 'Clothing':
  567. initialValue = values[4]
  568. newValue = float(initialValue) + float(obtainedCategoryValue)
  569. cursor.execute(''' UPDATE users SET clothing = ? WHERE username = ? ''', (newValue, GetLoginName,))
  570. db.commit()
  571. testB = cursor.execute(''' SELECT clothingbudget FROM users WHERE username = ? ''',
  572. (GetLoginName,)).fetchone()
  573. testU = cursor.execute(''' SELECT clothing FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  574. if float(testB[0]) > 0.0:
  575. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  576. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  577. tkinter.messagebox.showwarning("Warning",
  578. "You surpassed 70 percent of your budget for Clothing. Be wise with your spendings.")
  579. else:
  580. tkinter.messagebox.showwarning("Warning",
  581. "You have exceeded the budget for Clothing. Be extra careful with your money.")
  582. else:
  583. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  584.  
  585. elif obtainedCategory == 'Transport':
  586. initialValue = values[5]
  587. newValue = float(initialValue) + float(obtainedCategoryValue)
  588. cursor.execute(''' UPDATE users SET transport = ? WHERE username = ? ''', (newValue, GetLoginName,))
  589. db.commit()
  590. testB = cursor.execute(''' SELECT transportbudget FROM users WHERE username = ? ''',
  591. (GetLoginName,)).fetchone()
  592. testU = cursor.execute(''' SELECT transport FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  593. if float(testB[0]) > 0.0:
  594. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  595. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  596. tkinter.messagebox.showwarning("Warning",
  597. "You surpassed 70 percent of your budget for Transport. Be wise with your spendings.")
  598. else:
  599. tkinter.messagebox.showwarning("Warning",
  600. "You have exceeded the budget for Transport. Be extra careful with your money.")
  601. else:
  602. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  603.  
  604. elif obtainedCategory == 'Utilities':
  605. initialValue = values[6]
  606. newValue = float(initialValue) + float(obtainedCategoryValue)
  607. cursor.execute(''' UPDATE users SET utilities = ? WHERE username = ? ''', (newValue, GetLoginName,))
  608. db.commit()
  609. testB = cursor.execute(''' SELECT utilitiesbudget FROM users WHERE username = ? ''',
  610. (GetLoginName,)).fetchone()
  611. testU = cursor.execute(''' SELECT utilities FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  612. if float(testB[0]) > 0.0:
  613. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  614. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  615. tkinter.messagebox.showwarning("Warning",
  616. "You surpassed 70 percent of your budget for Utilities. Be wise with your spendings.")
  617. else:
  618. tkinter.messagebox.showwarning("Warning",
  619. "You have exceeded the budget for Utilities. Be extra careful with your money.")
  620. else:
  621. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  622.  
  623. elif obtainedCategory == 'Health Care':
  624. initialValue = values[7]
  625. newValue = float(initialValue) + float(obtainedCategoryValue)
  626. cursor.execute(''' UPDATE users SET health = ? WHERE username = ? ''', (newValue, GetLoginName,))
  627. db.commit()
  628. testB = cursor.execute(''' SELECT healthbudget FROM users WHERE username = ? ''',
  629. (GetLoginName,)).fetchone()
  630. testU = cursor.execute(''' SELECT health FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  631. if float(testB[0]) > 0.0:
  632. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  633. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  634. tkinter.messagebox.showwarning("Warning",
  635. "You surpassed 70 percent of your budget for Health Care. Be wise with your spendings.")
  636. else:
  637. tkinter.messagebox.showwarning("Warning",
  638. "You have exceeded the budget for Health Care. Be extra careful with your money.")
  639. else:
  640. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  641.  
  642. elif obtainedCategory == 'Insurance':
  643. initialValue = values[8]
  644. newValue = float(initialValue) + float(obtainedCategoryValue)
  645. cursor.execute(''' UPDATE users SET insurance = ? WHERE username = ? ''', (newValue, GetLoginName,))
  646. db.commit()
  647. testB = cursor.execute(''' SELECT insurancebudget FROM users WHERE username = ? ''',
  648. (GetLoginName,)).fetchone()
  649. testU = cursor.execute(''' SELECT insurance FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  650. if float(testB[0]) > 0.0:
  651. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  652. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  653. tkinter.messagebox.showwarning("Warning",
  654. "You surpassed 70 percent of your budget for Insurance. Be wise with your spendings.")
  655. else:
  656. tkinter.messagebox.showwarning("Warning",
  657. "You have exceeded the budget for Insurance. Be extra careful with your money.")
  658. else:
  659. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  660.  
  661. elif obtainedCategory == 'Others':
  662. initialValue = values[9]
  663. newValue = float(initialValue) + float(obtainedCategoryValue)
  664. cursor.execute(''' UPDATE users SET others = ? WHERE username = ? ''', (newValue, GetLoginName,))
  665. db.commit()
  666. testB = cursor.execute(''' SELECT othersbudget FROM users WHERE username = ? ''',
  667. (GetLoginName,)).fetchone()
  668. testU = cursor.execute(''' SELECT others FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  669. if float(testB[0]) > 0.0:
  670. if ((float(testU[0]) / float(testB[0])) * 100) < 100:
  671. if ((float(testU[0]) / float(testB[0])) * 100) > 70:
  672. tkinter.messagebox.showwarning("Warning",
  673. "You surpassed 70 percent of your budget for Others. Be wise with your spendings.")
  674. else:
  675. tkinter.messagebox.showwarning("Warning",
  676. "You have exceeded the budget for Others. Be extra careful with your money.")
  677. else:
  678. tkinter.messagebox.showwarning("Warning", "You have entered expenditure without adding a budget")
  679.  
  680. tkinter.messagebox.showinfo("Success", "Value successfully registered!")
  681. else:
  682. tkinter.messagebox.showerror("Error", "Please enter a valid value")
  683. else:
  684. tkinter.messagebox.showerror("Error", "Please enter a value")
  685.  
  686. inputCategoryValue.delete(0, END)
  687. inputCategoryValue.insert(0, "")
  688.  
  689. def backToMainUI():
  690. LoginFrame.pack_forget()
  691. RegisterFrame.pack_forget()
  692. ExpenditureInterface.pack_forget()
  693. ProfileFrame.pack_forget()
  694. BudgetingFrame.pack_forget()
  695. SummaryFrame.pack_forget()
  696. HistoryFrame.pack_forget()
  697. MainInterfaceFrame.pack()
  698.  
  699. def onClickSave():
  700. global getTestUsername
  701. global getNewPassword
  702. global getConfirmNewPassword
  703. getTestUsername = e1.get()
  704. getNewPassword = e2.get()
  705. getConfirmNewPassword = e3.get()
  706. if getTestUsername != GetLoginName:
  707. tkinter.messagebox.showerror("Error", "The username entered is not the same as the one used to log in!")
  708. elif getNewPassword != getConfirmNewPassword:
  709. tkinter.messagebox.showerror("Error", "Passwords do not match. Please try again.")
  710. elif getNewPassword == getTestUsername:
  711. tkinter.messagebox.showerror("Error", "Password cannot be the same as the username for security purposes")
  712. else:
  713. cursor.execute(''' UPDATE users SET password = ? WHERE username = ? ''', (getNewPassword, getTestUsername,))
  714. db.commit()
  715. tkinter.messagebox.showinfo("Success", "Successfully changed password. You can now use your new password to log in.")
  716. e1.delete(0, END)
  717. e1.insert(0, "")
  718. e2.delete(0, END)
  719. e2.insert(0, "")
  720. e3.delete(0, END)
  721. e3.insert(0, "")
  722.  
  723. def onClickSummary():
  724. MainInterfaceFrame.pack_forget()
  725. SummaryFrame.pack()
  726. monthEndDate = cursor.execute(''' SELECT dateafteronemonth FROM users WHERE username = ?''', (GetLoginName,)).fetchone()
  727. today = datetime.datetime.today()
  728. daysLeft = Label(SummaryFrame, text=(datetime.datetime.strptime(monthEndDate[0], '%Y-%m-%d %H:%M:%S.%f') - today).days)
  729. daysLeft.grid(row=1, column=1)
  730.  
  731. cursor.execute(''' SELECT foodbudget, educationbudget, groceriesbudget, fuelbudget, clothingbudget, transportbudget,
  732. utilitiesbudget, healthbudget, insurancebudget, othersbudget FROM users WHERE username=?''',
  733. (GetLoginName,))
  734. budgetValues = cursor.fetchone()
  735.  
  736. cursor.execute(''' SELECT food, education, groceries, fuel, clothing, transport,
  737. utilities, health, insurance, others FROM users WHERE username=?''',
  738. (GetLoginName,))
  739. usageValues = cursor.fetchone()
  740.  
  741. TotalBudget = 0
  742. for values in budgetValues:
  743. TotalBudget = TotalBudget + values
  744.  
  745. global TotalUsage
  746. global highestUsage
  747. global lowestUsage
  748. global highestUsageCat
  749. global lowestUsageCat
  750.  
  751. TotalUsage = 0
  752. highestUsage = 0
  753. lowestUsage = 99999999999999999999999
  754. highestUsageCat = 'Nil'
  755. lowestUsageCat = 'Nil'
  756. counter = 0
  757.  
  758. for values in usageValues:
  759. TotalUsage = TotalUsage + values
  760. if values > highestUsage:
  761. highestUsage = values
  762. if counter == 0:
  763. highestUsageCat = 'Food'
  764. elif counter == 1:
  765. highestUsageCat = 'Education'
  766. elif counter == 2:
  767. highestUsageCat = 'Groceries'
  768. elif counter == 3:
  769. highestUsageCat = 'Fuel'
  770. elif counter == 4:
  771. highestUsageCat = 'Clothing'
  772. elif counter == 5:
  773. highestUsageCat = 'Transport'
  774. elif counter == 6:
  775. highestUsageCat = 'Utilities'
  776. elif counter == 7:
  777. highestUsageCat = 'Health'
  778. elif counter == 8:
  779. highestUsageCat = 'Insurance'
  780. elif counter == 9:
  781. highestUsageCat = 'Others'
  782. counter = counter + 1
  783. counter = 0
  784. for values in usageValues:
  785. if values < lowestUsage and values != 0:
  786. lowestUsage = values
  787. if counter == 0:
  788. lowestUsageCat = 'Food'
  789. elif counter == 1:
  790. lowestUsageCat = 'Education'
  791. elif counter == 2:
  792. lowestUsageCat = 'Groceries'
  793. elif counter == 3:
  794. lowestUsageCat = 'Fuel'
  795. elif counter == 4:
  796. lowestUsageCat = 'Clothing'
  797. elif counter == 5:
  798. lowestUsageCat = 'Transport'
  799. elif counter == 6:
  800. lowestUsageCat = 'Utilities'
  801. elif counter == 7:
  802. lowestUsageCat = 'Health'
  803. elif counter == 8:
  804. lowestUsageCat = 'Insurance'
  805. elif counter == 9:
  806. lowestUsageCat = 'Others'
  807.  
  808. counter = counter + 1
  809.  
  810. if lowestUsage == 99999999999999999999999:
  811. lowestUsage = 0
  812. if highestUsageCat == 'Nil':
  813. highestUsageCat = 'TBD'
  814. if lowestUsageCat == 'Nil':
  815. lowestUsageCat = 'TBD'
  816.  
  817. quotaleft = TotalBudget - TotalUsage
  818. if quotaleft == 0:
  819. quotaleft = 0
  820. elif quotaleft < 0:
  821. quotaleft = str(quotaleft) + " ,the negative sign indicates the amount has exceeded the budget"
  822. averagedaily = 0
  823. Days = 30.0 - float((datetime.datetime.strptime(monthEndDate[0], '%Y-%m-%d %H:%M:%S.%f') - today).days)
  824. if Days != 0:
  825. averagedaily = TotalUsage / Days
  826. else:
  827. averagedaily = TotalUsage
  828.  
  829. food = cursor.execute(''' SELECT food FROM users where username = ? ''',
  830. (GetLoginName,)).fetchone()
  831. education = cursor.execute(''' SELECT education FROM users where username = ? ''',
  832. (GetLoginName,)).fetchone()
  833. groceries = cursor.execute(''' SELECT groceries FROM users where username = ? ''',
  834. (GetLoginName,)).fetchone()
  835. fuel = cursor.execute(''' SELECT fuel FROM users where username = ? ''',
  836. (GetLoginName,)).fetchone()
  837. clothing = cursor.execute(''' SELECT clothing FROM users where username = ? ''',
  838. (GetLoginName,)).fetchone()
  839. transport = cursor.execute(''' SELECT transport FROM users where username = ? ''',
  840. (GetLoginName,)).fetchone()
  841. utilities = cursor.execute(''' SELECT utilities FROM users where username = ? ''',
  842. (GetLoginName,)).fetchone()
  843. health = cursor.execute(''' SELECT health FROM users where username = ? ''',
  844. (GetLoginName,)).fetchone()
  845. insurance = cursor.execute(''' SELECT insurance FROM users where username = ? ''',
  846. (GetLoginName,)).fetchone()
  847. others = cursor.execute(''' SELECT others FROM users where username = ? ''',
  848. (GetLoginName,)).fetchone()
  849.  
  850. QuotaLeftLabel = Label(SummaryFrame, text=quotaleft)
  851. QuotaLeftLabel.grid(row=2, column=1)
  852.  
  853. TotalExpensesLabel = Label(SummaryFrame, text=TotalUsage)
  854. TotalExpensesLabel.grid(row=3, column=1)
  855.  
  856. HighestUsageLabel = Label(SummaryFrame, text=str(highestUsageCat) + ', ' + str(highestUsage))
  857. HighestUsageLabel.grid(row=4, column=1)
  858.  
  859. LowestUsageLabel = Label(SummaryFrame, text=str(lowestUsageCat) + ', ' + str(lowestUsage))
  860. LowestUsageLabel.grid(row=5, column=1)
  861.  
  862. averagedailylabel = Label(SummaryFrame, text=averagedaily)
  863. averagedailylabel.grid(row=6, column=1)
  864.  
  865. Label(SummaryFrame, text="Expenditure for Food: ").grid(row=7, column=0, sticky=E)
  866. foodsummary = Label(SummaryFrame, text=food[0])
  867. foodsummary.grid(row=7, column=1)
  868.  
  869. Label(SummaryFrame, text="Expenditure for Education: ").grid(row=8, column=0, sticky=E)
  870. educationsummary = Label(SummaryFrame, text=education[0])
  871. educationsummary.grid(row=8, column=1)
  872.  
  873. Label(SummaryFrame, text="Expenditure for Groceries: ").grid(row=9, column=0, sticky=E)
  874. groceriessummary = Label(SummaryFrame, text=groceries[0])
  875. groceriessummary.grid(row=9, column=1)
  876.  
  877. Label(SummaryFrame, text="Expenditure for Fuel: ").grid(row=10, column=0, sticky=E)
  878. fuelsummary = Label(SummaryFrame, text=fuel[0])
  879. fuelsummary.grid(row=10, column=1)
  880.  
  881. Label(SummaryFrame, text="Expenditure for Clothing: ").grid(row=11, column=0, sticky=E)
  882. clothingsummary = Label(SummaryFrame, text=clothing[0])
  883. clothingsummary.grid(row=11, column=1)
  884.  
  885. Label(SummaryFrame, text="Expenditure for Transport: ").grid(row=12, column=0, sticky=E)
  886. transportsummary = Label(SummaryFrame, text=transport[0])
  887. transportsummary.grid(row=12, column=1)
  888.  
  889. Label(SummaryFrame, text="Expenditure for Utilites: ").grid(row=13, column=0, sticky=E)
  890. utilitiessummary = Label(SummaryFrame, text=utilities[0])
  891. utilitiessummary.grid(row=13, column=1)
  892.  
  893. Label(SummaryFrame, text="Expenditure for Health Care: ").grid(row=14, column=0, sticky=E)
  894. healthsummary = Label(SummaryFrame, text=health[0])
  895. healthsummary.grid(row=14, column=1)
  896.  
  897. Label(SummaryFrame, text="Expenditure for Insurance: ").grid(row=15, column=0, sticky=E)
  898. insurancesummary = Label(SummaryFrame, text=insurance[0])
  899. insurancesummary.grid(row=15, column=1)
  900.  
  901. Label(SummaryFrame, text="Expenditure for Others: ").grid(row=16, column=0, sticky=E)
  902. otherssummary = Label(SummaryFrame, text=others[0])
  903. otherssummary.grid(row=16, column=1)
  904.  
  905. def backSummary():
  906. daysLeft.grid_forget()
  907. QuotaLeftLabel.grid_forget()
  908. TotalExpensesLabel.grid_forget()
  909. HighestUsageLabel.grid_forget()
  910. LowestUsageLabel.grid_forget()
  911. averagedailylabel.grid_forget()
  912. foodsummary.grid_forget()
  913. educationsummary.grid_forget()
  914. groceriessummary.grid_forget()
  915. fuelsummary.grid_forget()
  916. clothingsummary.grid_forget()
  917. transportsummary.grid_forget()
  918. utilitiessummary.grid_forget()
  919. healthsummary.grid_forget()
  920. insurancesummary.grid_forget()
  921. otherssummary.grid_forget()
  922. SummaryFrame.pack_forget()
  923. MainInterfaceFrame.pack()
  924.  
  925. button1 = Button(SummaryFrame, text="Back", command=backSummary)
  926. button1.grid(row=17, columnspan=3, sticky=E)
  927.  
  928.  
  929.  
  930.  
  931. def onClickBudgeting():
  932. MainInterfaceFrame.pack_forget()
  933. BudgetingFrame.pack()
  934.  
  935. getFoodBudget = cursor.execute(''' SELECT foodbudget FROM users WHERE username = ?''',
  936. (GetLoginName,)).fetchone()
  937. foodbudgetlabel = Label(BudgetingFrame, text=getFoodBudget[0])
  938. foodbudgetlabel.grid(row=0, column=0)
  939.  
  940. getEducationBudget = cursor.execute(''' SELECT educationbudget FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  941. educationbudgetlabel = Label(BudgetingFrame, text=getEducationBudget[0])
  942. educationbudgetlabel.grid(row=1, column=0)
  943.  
  944. getGroceriesBudget = cursor.execute(''' SELECT groceriesbudget FROM users WHERE username = ? ''',
  945. (GetLoginName,)).fetchone()
  946. groceriesbudgetlabel = Label(BudgetingFrame, text=getGroceriesBudget[0])
  947. groceriesbudgetlabel.grid(row=2, column=0)
  948.  
  949. getFuelBudget = cursor.execute(''' SELECT fuelbudget FROM users WHERE username = ? ''',
  950. (GetLoginName,)).fetchone()
  951. fuelbudgetlabel = Label(BudgetingFrame, text=getFuelBudget[0])
  952. fuelbudgetlabel.grid(row=3, column=0)
  953.  
  954. getClothingBudget = cursor.execute(''' SELECT clothingbudget FROM users WHERE username = ? ''',
  955. (GetLoginName,)).fetchone()
  956. clothingbudgetlabel = Label(BudgetingFrame, text=getClothingBudget[0])
  957. clothingbudgetlabel.grid(row=4, column=0)
  958.  
  959. getTransportBudget = cursor.execute(''' SELECT transportbudget FROM users WHERE username = ? ''',
  960. (GetLoginName,)).fetchone()
  961. transportbudgetlabel = Label(BudgetingFrame, text=getTransportBudget[0])
  962. transportbudgetlabel.grid(row=5, column=0)
  963.  
  964. getUtilitiesBudget = cursor.execute(''' SELECT utilitiesbudget FROM users WHERE username = ? ''',
  965. (GetLoginName,)).fetchone()
  966. utilitiesbudgetlabel = Label(BudgetingFrame, text=getUtilitiesBudget[0])
  967. utilitiesbudgetlabel.grid(row=6, column=0)
  968.  
  969. getHealthBudget = cursor.execute(''' SELECT healthbudget FROM users WHERE username = ? ''',
  970. (GetLoginName,)).fetchone()
  971. healthbudgetlabel = Label(BudgetingFrame, text=getHealthBudget[0])
  972. healthbudgetlabel.grid(row=7, column=0)
  973.  
  974. getInsuranceBudget = cursor.execute(''' SELECT insurancebudget FROM users WHERE username = ? ''',
  975. (GetLoginName,)).fetchone()
  976. insurancebudgetlabel = Label(BudgetingFrame, text=getInsuranceBudget[0])
  977. insurancebudgetlabel.grid(row=8, column=0)
  978.  
  979. getOthersBudget = cursor.execute(''' SELECT othersbudget FROM users WHERE username = ? ''',
  980. (GetLoginName,)).fetchone()
  981. othersbudgetlabel = Label(BudgetingFrame, text=getOthersBudget[0])
  982. othersbudgetlabel.grid(row=9, column=0)
  983.  
  984. def onClickHistory():
  985. global getMonthNumber
  986. global monthHistoryEntry
  987. global CheckHistory1
  988. getMonthNumber = cursor.execute(''' SELECT monthnumber FROM users WHERE username = ? ''', (GetLoginName,)).fetchone()
  989. Label(HistoryFrame, text="Our records show that you have history for data for " + str(getMonthNumber[0]) + " months. \n Please enter the number of months previosly to view the history for that month").grid(row=0, columnspan=2)
  990. monthHistoryEntry = Entry(HistoryFrame)
  991. monthHistoryEntry.grid(row=1, columnspan=2)
  992. monthHistoryEntry.focus_set()
  993. CheckHistory1 = Button(HistoryFrame, text="Enter", command=historyEnter1)
  994. CheckHistory1.grid(row=2, columnspan=2)
  995. backhistory = Button(HistoryFrame, text="Back", command=backToMainUI)
  996. backhistory.grid(row=30, columnspan=2)
  997.  
  998. MainInterfaceFrame.pack_forget()
  999. HistoryFrame.pack()
  1000.  
  1001. def historyEnter1():
  1002. CheckHistory1.grid_forget()
  1003. number = monthHistoryEntry.get()
  1004. names = []
  1005. rowid = []
  1006. MonthNumber = []
  1007. specificuser = 0
  1008.  
  1009. for row in cursor.execute(''' SELECT username FROM history ''').fetchall():
  1010. names.append(row[0])
  1011.  
  1012. for row in cursor.execute(''' SELECT id FROM history ''').fetchall():
  1013. rowid.append(row[0])
  1014.  
  1015. for row in cursor.execute(''' SELECT monthnumber FROM history ''').fetchall():
  1016. MonthNumber.append(row[0])
  1017.  
  1018. if str(number).isdigit():
  1019. if int(number) <= int(getMonthNumber[0]):
  1020. c = 0
  1021. for username in names:
  1022. if username == GetLoginName:
  1023. if MonthNumber[c] == int(number):
  1024. specificuser = rowid[c]
  1025. c = c + 1
  1026.  
  1027. Label(HistoryFrame, text="Food Budget: ").grid(row=3, column=0, sticky=E)
  1028. getFoodBudget = cursor.execute(''' SELECT foodbudget FROM history WHERE id = ?''',
  1029. (specificuser,)).fetchone()
  1030. foodbudgetlabel = Label(HistoryFrame, text=getFoodBudget)
  1031. foodbudgetlabel.grid(row=3, column=1, sticky=W)
  1032.  
  1033. Label(HistoryFrame, text="Education Budget: ").grid(row=4, column=0, sticky=E)
  1034. getEducationBudget = cursor.execute(''' SELECT education FROM history WHERE id = ?''',
  1035. (specificuser,)).fetchone()
  1036. educationbudgetlabel = Label(HistoryFrame, text=getEducationBudget)
  1037. educationbudgetlabel.grid(row=4, column=1, sticky=W)
  1038.  
  1039. Label(HistoryFrame, text="Groceries Budget: ").grid(row=5, column=0, sticky=E)
  1040. getGroceriesBudget = cursor.execute(''' SELECT groceriesbudget FROM history WHERE id = ?''',
  1041. (specificuser,)).fetchone()
  1042. groceriesbudgetlabel = Label(HistoryFrame, text=getGroceriesBudget)
  1043. groceriesbudgetlabel.grid(row=5, column=1, sticky=W)
  1044.  
  1045. Label(HistoryFrame, text="Fuel Budget: ").grid(row=6, column=0, sticky=E)
  1046. getFuelBudget = cursor.execute(''' SELECT fuelbudget FROM history WHERE id = ?''',
  1047. (specificuser,)).fetchone()
  1048. fuelbudgetlabel = Label(HistoryFrame, text=getFuelBudget)
  1049. fuelbudgetlabel.grid(row=6, column=1, sticky=W)
  1050.  
  1051. Label(HistoryFrame, text="Clothing Budget: ").grid(row=7, column=0, sticky=E)
  1052. getClothingBudget = cursor.execute(''' SELECT clothingbudget FROM history WHERE id = ?''',
  1053. (specificuser,)).fetchone()
  1054. clothingbudgetlabel = Label(HistoryFrame, text=getClothingBudget)
  1055. clothingbudgetlabel.grid(row=7, column=1, sticky=W)
  1056.  
  1057. Label(HistoryFrame, text="Transport Budget: ").grid(row=8, column=0, sticky=E)
  1058. getTransportBudget = cursor.execute(''' SELECT transportbudget FROM history WHERE id = ?''',
  1059. (specificuser,)).fetchone()
  1060. transportbudgetlabel = Label(HistoryFrame, text=getTransportBudget)
  1061. transportbudgetlabel.grid(row=8, column=1, sticky=W)
  1062.  
  1063. Label(HistoryFrame, text="Utilities Budget: ").grid(row=9, column=0, sticky=E)
  1064. getUtilitiesBudget = cursor.execute(''' SELECT utilitiesbudget FROM history WHERE id = ?''',
  1065. (specificuser,)).fetchone()
  1066. utilitiesbudgetlabel = Label(HistoryFrame, text=getUtilitiesBudget)
  1067. utilitiesbudgetlabel.grid(row=9, column=1, sticky=W)
  1068.  
  1069. Label(HistoryFrame, text="Health Budget: ").grid(row=10, column=0, sticky=E)
  1070. getHealthBudget = cursor.execute(''' SELECT healthbudget FROM history WHERE id = ?''',
  1071. (specificuser,)).fetchone()
  1072. healthbudgetlabel = Label(HistoryFrame, text=getHealthBudget)
  1073. healthbudgetlabel.grid(row=10, column=1, sticky=W)
  1074.  
  1075. Label(HistoryFrame, text="Insurance Budget: ").grid(row=11, column=0, sticky=E)
  1076. getInsuranceBudget = cursor.execute(''' SELECT insurancebudget FROM history WHERE id = ?''',
  1077. (specificuser,)).fetchone()
  1078. insurancebudgetlabel = Label(HistoryFrame, text=getInsuranceBudget)
  1079. insurancebudgetlabel.grid(row=11, column=1, sticky=W)
  1080.  
  1081. Label(HistoryFrame, text="Others Budget: ").grid(row=12, column=0, sticky=E)
  1082. getOthersBudget = cursor.execute(''' SELECT othersbudget FROM history WHERE id = ?''',
  1083. (specificuser,)).fetchone()
  1084. othersbudgetlabel = Label(HistoryFrame, text=getOthersBudget)
  1085. othersbudgetlabel.grid(row=12, column=1, sticky=W)
  1086.  
  1087. Label(HistoryFrame, text="Food Expenditure: ").grid(row=13, column=0, sticky=E)
  1088. getFood = cursor.execute(''' SELECT food FROM history WHERE id = ?''',
  1089. (specificuser,)).fetchone()
  1090. foodlabel = Label(HistoryFrame, text=getFood)
  1091. foodlabel.grid(row=13, column=1, sticky=W)
  1092.  
  1093. Label(HistoryFrame, text="Education Expenditure: ").grid(row=14, column=0, sticky=E)
  1094. getEducation = cursor.execute(''' SELECT education FROM history WHERE id = ?''',
  1095. (specificuser,)).fetchone()
  1096. educationlabel = Label(HistoryFrame, text=getEducation)
  1097. educationlabel.grid(row=14, column=1, sticky=W)
  1098.  
  1099. Label(HistoryFrame, text="Groceries Expenditure: ").grid(row=15, column=0, sticky=E)
  1100. getGroceries = cursor.execute(''' SELECT groceries FROM history WHERE id = ?''',
  1101. (specificuser,)).fetchone()
  1102. grocerieslabel = Label(HistoryFrame, text=getGroceries)
  1103. grocerieslabel.grid(row=15, column=1, sticky=W)
  1104.  
  1105. Label(HistoryFrame, text="Fuel Expenditure: ").grid(row=16, column=0, sticky=E)
  1106. getFuel = cursor.execute(''' SELECT fuel FROM history WHERE id = ?''',
  1107. (specificuser,)).fetchone()
  1108. fuellabel = Label(HistoryFrame, text=getFuel)
  1109. fuellabel.grid(row=16, column=1, sticky=W)
  1110.  
  1111. Label(HistoryFrame, text="Clothing Expenditure: ").grid(row=17, column=0, sticky=E)
  1112. getClothing = cursor.execute(''' SELECT clothing FROM history WHERE id = ?''',
  1113. (specificuser,)).fetchone()
  1114. clothinglabel = Label(HistoryFrame, text=getClothing)
  1115. clothinglabel.grid(row=17, column=1, sticky=W)
  1116.  
  1117. Label(HistoryFrame, text="Transport Expenditure: ").grid(row=18, column=0, sticky=E)
  1118. getTransport = cursor.execute(''' SELECT transport FROM history WHERE id = ?''',
  1119. (specificuser,)).fetchone()
  1120. transportlabel = Label(HistoryFrame, text=getTransport)
  1121. transportlabel.grid(row=18, column=1, sticky=W)
  1122.  
  1123. Label(HistoryFrame, text="Utilities Expenditure: ").grid(row=19, column=0, sticky=E)
  1124. getUtilities = cursor.execute(''' SELECT utilities FROM history WHERE id = ?''',
  1125. (specificuser,)).fetchone()
  1126. utilitieslabel = Label(HistoryFrame, text=getUtilities)
  1127. utilitieslabel.grid(row=19, column=1, sticky=W)
  1128.  
  1129. Label(HistoryFrame, text="Health Expenditure: ").grid(row=20, column=0, sticky=E)
  1130. getHealth = cursor.execute(''' SELECT health FROM history WHERE id = ?''',
  1131. (specificuser,)).fetchone()
  1132. healthlabel = Label(HistoryFrame, text=getHealth)
  1133. healthlabel.grid(row=20, column=1, sticky=W)
  1134.  
  1135. Label(HistoryFrame, text="Insurance Expenditure: ").grid(row=21, column=0, sticky=E)
  1136. getInsurance = cursor.execute(''' SELECT insurance FROM history WHERE id = ?''',
  1137. (specificuser,)).fetchone()
  1138. insurancelabel = Label(HistoryFrame, text=getInsurance)
  1139. insurancelabel.grid(row=21, column=1, sticky=W)
  1140.  
  1141. Label(HistoryFrame, text="Others Expenditure: ").grid(row=22, column=0, sticky=E)
  1142. getOthers = cursor.execute(''' SELECT others FROM history WHERE id = ?''',
  1143. (specificuser,)).fetchone()
  1144. otherslabel = Label(HistoryFrame, text=getOthers)
  1145. otherslabel.grid(row=22, column=1, sticky=W)
  1146.  
  1147. Label(HistoryFrame, text="Total Budget: ").grid(row=23, column=0, sticky=E)
  1148. getTotalBudget = cursor.execute(''' SELECT totalbudget FROM history WHERE id = ?''',
  1149. (specificuser,)).fetchone()
  1150. totalbudgetlabel = Label(HistoryFrame, text=getTotalBudget)
  1151. totalbudgetlabel.grid(row=23, column=1, sticky=W)
  1152.  
  1153. Label(HistoryFrame, text="Total Usage: ").grid(row=24, column=0, sticky=E)
  1154. getTotalUsage = cursor.execute(''' SELECT totalusage FROM history WHERE id = ?''',
  1155. (specificuser,)).fetchone()
  1156. totalusagelabel = Label(HistoryFrame, text=getTotalUsage)
  1157. totalusagelabel.grid(row=24, column=1, sticky=W)
  1158.  
  1159. def historyEnter2():
  1160. foodbudgetlabel.grid_forget()
  1161. educationbudgetlabel.grid_forget()
  1162. groceriesbudgetlabel.grid_forget()
  1163. fuelbudgetlabel.grid_forget()
  1164. clothingbudgetlabel.grid_forget()
  1165. transportbudgetlabel.grid_forget()
  1166. utilitiesbudgetlabel.grid_forget()
  1167. healthbudgetlabel.grid_forget()
  1168. insurancebudgetlabel.grid_forget()
  1169. othersbudgetlabel.grid_forget()
  1170. foodlabel.grid_forget()
  1171. educationlabel.grid_forget()
  1172. grocerieslabel.grid_forget()
  1173. fuellabel.grid_forget()
  1174. clothinglabel.grid_forget()
  1175. transportlabel.grid_forget()
  1176. utilitieslabel.grid_forget()
  1177. healthlabel.grid_forget()
  1178. insurancelabel.grid_forget()
  1179. otherslabel.grid_forget()
  1180. totalbudgetlabel.grid_forget()
  1181. totalusagelabel.grid_forget()
  1182. historyEnter1()
  1183.  
  1184. CheckHistory2 = Button(HistoryFrame, text="Enter", command=historyEnter2)
  1185. CheckHistory2.grid(row=2, columnspan=2)
  1186.  
  1187.  
  1188.  
  1189. else:
  1190. tkinter.messagebox.showerror("Error", "Please enter a number which is in range of the previous months")
  1191. else:
  1192. tkinter.messagebox.showerror("Error", "Please enter a valid number for the months")
  1193.  
  1194. def quit():
  1195. exit()
  1196.  
  1197. '''
  1198.  
  1199. LOGIN FRAME
  1200.  
  1201. '''
  1202. photo = PhotoImage(file="savely.png")
  1203. label = Label(LoginFrame, image=photo)
  1204. label.grid(row=0, columnspan=2, sticky=E)
  1205.  
  1206.  
  1207. label_1 = Label(LoginFrame, text="Name: ") #Display the text(name) in login page
  1208. label_2 = Label(LoginFrame, text="Password:") #Display the text(password) in login page
  1209. entry_1 = Entry(LoginFrame) #Creates a field for users to enter their login name
  1210. entry_2 = Entry(LoginFrame) #Creates a field for users to enter their login password
  1211. entry_2.config(show='*')
  1212. entry_1.focus_set() #Tells the program to focus on user login name input
  1213. entry_2.focus_set() #Tells the program to focus on user login password input
  1214.  
  1215. label_1.grid(row=1, column=0, sticky=E)
  1216. label_2.grid(row=2, column=0, sticky=E)
  1217.  
  1218. entry_1.grid(row=1, column=1)
  1219. entry_2.grid(row=2, column=1)
  1220.  
  1221. LoginButton = Button(LoginFrame, text="Login", fg="blue", command=LoginCredentials)
  1222. LoginButton.grid(columnspan=2)
  1223.  
  1224. RegisterButton = Button(LoginFrame, text="Register", fg="blue", command=LoginRegisterClicked)
  1225. RegisterButton.grid(columnspan=2)
  1226.  
  1227. QuitButton = Button(LoginFrame, text="Exit Program", fg="blue", command=quit)
  1228. QuitButton.grid(columnspan=2)
  1229.  
  1230. '''
  1231.  
  1232. END LOGIN FRAME
  1233.  
  1234. '''
  1235.  
  1236. '''
  1237.  
  1238. REGISTER FRAME
  1239.  
  1240. '''
  1241.  
  1242. Info_1 = Label(RegisterFrame, text="Username")
  1243. Info_2 = Label(RegisterFrame, text="Password")
  1244. Info_3 = Label(RegisterFrame, text="Confirm Password")
  1245. TextRegister = Button(RegisterFrame, text="Register", fg="blue", command=RegisterClicked)
  1246. TextRegister.grid(row=3, columnspan=2)
  1247. RegFrameBackLogin = Button(RegisterFrame,text="Go back to login", fg="blue", command=fromRegToLogPage)
  1248. RegFrameBackLogin.grid(row=4, columnspan=2)
  1249.  
  1250. InfoInput_1 = Entry(RegisterFrame)
  1251. InfoInput_2 = Entry(RegisterFrame)
  1252. InfoInput_2.config(show='*')
  1253. InfoInput_3 = Entry(RegisterFrame)
  1254. InfoInput_3.config(show='*')
  1255. InfoInput_1.focus_set()
  1256. InfoInput_2.focus_set()
  1257. InfoInput_3.focus_set()
  1258.  
  1259. Info_1.grid(row=0, column=0, sticky=E)
  1260. Info_2.grid(row=1, column=0, sticky=E)
  1261. Info_3.grid(row=2, column=0, sticky=E)
  1262.  
  1263. InfoInput_1.grid(row=0, column=1)
  1264. InfoInput_2.grid(row=1, column=1)
  1265. InfoInput_3.grid(row=2, column=1)
  1266.  
  1267.  
  1268.  
  1269. '''
  1270.  
  1271. END REGISTER FRAME
  1272.  
  1273. '''
  1274.  
  1275.  
  1276.  
  1277. ''''
  1278.  
  1279. MAIN INTERFACE
  1280.  
  1281. '''
  1282.  
  1283. def logout():
  1284. MainInterfaceFrame.pack_forget()
  1285. LoginFrame.pack()
  1286.  
  1287. budgetingButton = Button(MainInterfaceFrame, text="Budgeting", command=onClickBudgeting, bg="green", fg="white", activebackground="white", activeforeground="green", font=('Verdana',15))
  1288. budgetingButton.pack(ipadx=9999, ipady=10)
  1289.  
  1290. expenditureButton = Button(MainInterfaceFrame, text="Expenditure", command=onClickExpenditure, bg="blue", fg="white", activebackground="white", activeforeground="blue", font=('Verdana',15))
  1291. expenditureButton.pack(ipadx=9999, ipady=10)
  1292.  
  1293. summaryButton = Button(MainInterfaceFrame, text="Summary", command=onClickSummary, bg="red", fg="white", activebackground="white", activeforeground="red", font=('Verdana',15))
  1294. summaryButton.pack(ipadx=9999, ipady=10)
  1295.  
  1296. profileButton = Button(MainInterfaceFrame, text="Profile", command=onClickProfile, bg="orange", fg="white", activebackground="white", activeforeground="orange", font=('Verdana',15))
  1297. profileButton.pack(ipadx=9999, ipady=10)
  1298.  
  1299. historyButton = Button(MainInterfaceFrame, text="History", command=onClickHistory, bg="purple", fg="white", activebackground="white", activeforeground="purple", font=('Verdana',15))
  1300. historyButton.pack(ipadx=9999, ipady=10)
  1301.  
  1302. logOutButton = Button(MainInterfaceFrame, text="Log Out", bg="black", fg="white", activebackground="white", activeforeground="black", command=logout)
  1303. logOutButton.pack(pady=60, ipadx=100, ipady=10)
  1304.  
  1305. '''
  1306.  
  1307. END MAIN INTERFACE
  1308.  
  1309. '''
  1310.  
  1311. '''
  1312.  
  1313. EXPENDITURE INTERFACE
  1314.  
  1315. '''
  1316.  
  1317.  
  1318. expenditureLabel = Label(ExpenditureInterface, text="Expenditure \n\n Select a category from the drop down then input the amount you have spent on that category \n")
  1319. expenditureLabel.grid(row=0, columnspan=2)
  1320.  
  1321. categoryText = Label(ExpenditureInterface, text="Choose your category:")
  1322. categoryValueText = Label(ExpenditureInterface, text="Insert Value:")
  1323.  
  1324. variable = StringVar(ExpenditureInterface)
  1325. variable.set("Food") #default value
  1326.  
  1327. inputCategory = OptionMenu(ExpenditureInterface, variable, "Food", "Education", "Groceries", "Fuel",
  1328. "Clothing", "Transport", "Utilities", "Health Care", "Insurance", "Others")
  1329. inputCategoryValue = Entry(ExpenditureInterface)
  1330.  
  1331. insertValueButton = Button(ExpenditureInterface, text="Insert Value", command=onClickInsertValue)
  1332. backToMainUIButtonE = Button(ExpenditureInterface, text="Back", command=backToMainUI)
  1333.  
  1334. inputCategory.focus_set()
  1335. inputCategoryValue.focus_set()
  1336.  
  1337. categoryText.grid(row=1, column=0, sticky=E)
  1338. categoryValueText.grid(row=2, column=0, sticky=E)
  1339.  
  1340. inputCategory.grid(row=1, column=1)
  1341. inputCategoryValue.grid(row=2, column=1)
  1342.  
  1343. insertValueButton.grid(row=3, columnspan=2)
  1344. backToMainUIButtonE.grid(row=4, columnspan=2)
  1345.  
  1346.  
  1347.  
  1348.  
  1349. '''
  1350.  
  1351. END EXPENDITURE INTERFACE
  1352.  
  1353. '''
  1354.  
  1355. '''
  1356.  
  1357. PROFILE FRAME
  1358.  
  1359. '''
  1360.  
  1361. def notification():
  1362. getState = var.get()
  1363. cursor.execute(''' UPDATE users SET state = ? WHERE username = ? ''', (getState, GetLoginName))
  1364.  
  1365. Label(ProfileFrame, text="You can change your account password here. You may also choose to disable the notifications.\n").grid(row=0, columnspan=2)
  1366. Label(ProfileFrame, text="Username:").grid(row=1, column=0, sticky=E)
  1367. Label(ProfileFrame, text="Password:").grid(row=2, column=0, sticky=E)
  1368. Label(ProfileFrame, text="Confirm password:").grid(row=3, column=0, sticky=E)
  1369.  
  1370.  
  1371. e1 = Entry(ProfileFrame)
  1372. e2 = Entry(ProfileFrame)
  1373. e2.config(show='*')
  1374. e3 = Entry(ProfileFrame)
  1375. e3.config(show='*')
  1376. b1 = Button(ProfileFrame, text="Save", command=onClickSave)
  1377.  
  1378. e1.grid(row=1, column=1, sticky=W)
  1379. e2.grid(row=2, column=1, sticky=W)
  1380. e3.grid(row=3, column=1, sticky=W)
  1381. b1.grid(row=4, columnspan=2)
  1382.  
  1383. backToMainUIButtonE = Button(ProfileFrame, text="Back", command=backToMainUI)
  1384. backToMainUIButtonE.grid(row=5, columnspan=2)
  1385.  
  1386. var = IntVar()
  1387. c = Checkbutton(ProfileFrame, text="Toggle this button to turn notification on or off", variable=var, command=notification)
  1388. c.grid(row=6, columnspan=3, pady=50)
  1389.  
  1390. '''
  1391.  
  1392. END PROFILE FRAME
  1393.  
  1394. '''
  1395.  
  1396. '''
  1397.  
  1398. SUMMARY FRAME
  1399.  
  1400. '''
  1401.  
  1402. words = Label(SummaryFrame, text="Summary \n This page displays the summary of your expenditure \n", bg="green", fg="white")
  1403. Label1 = Label(SummaryFrame, text="Days left before month ends: ")
  1404. Label2 = Label(SummaryFrame, text="Quota left for the month: ")
  1405. Label3 = Label(SummaryFrame, text="Total expenses so far: ")
  1406. Label4 = Label(SummaryFrame, text="Highest expenditure so far by category: ")
  1407. Label5 = Label(SummaryFrame, text="Lowest expenditure so far by category: ")
  1408. Label16 = Label(SummaryFrame, text="Average daily expenditure: ")
  1409.  
  1410. words.grid(row=0, columnspan=3)
  1411. Label1.grid(row=1, column=0, sticky=E)
  1412. Label2.grid(row=2, column=0, sticky=E)
  1413. Label3.grid(row=3, column=0, sticky=E)
  1414. Label4.grid(row=4, column=0, sticky=E)
  1415. Label5.grid(row=5, column=0, sticky=E)
  1416. Label16.grid(row=6, column=0, sticky=E)
  1417.  
  1418.  
  1419. '''
  1420.  
  1421. END SUMMARY FRAME
  1422.  
  1423. '''
  1424.  
  1425.  
  1426. '''
  1427.  
  1428. BUDGETING FRAME
  1429.  
  1430. '''
  1431.  
  1432. def radButton1():
  1433. radEntry1.grid(column=2, row=0)
  1434. radEntry2.grid_forget()
  1435. radEntry3.grid_forget()
  1436. radEntry4.grid_forget()
  1437. radEntry5.grid_forget()
  1438. radEntry6.grid_forget()
  1439. radEntry7.grid_forget()
  1440. radEntry8.grid_forget()
  1441. radEntry9.grid_forget()
  1442. radEntry10.grid_forget()
  1443.  
  1444. def radButton2():
  1445. radEntry1.grid_forget()
  1446. radEntry2.grid(column=2, row=1)
  1447. radEntry3.grid_forget()
  1448. radEntry4.grid_forget()
  1449. radEntry5.grid_forget()
  1450. radEntry6.grid_forget()
  1451. radEntry7.grid_forget()
  1452. radEntry8.grid_forget()
  1453. radEntry9.grid_forget()
  1454. radEntry10.grid_forget()
  1455.  
  1456. def radButton3():
  1457. radEntry1.grid_forget()
  1458. radEntry2.grid_forget()
  1459. radEntry3.grid(column=2, row=2)
  1460. radEntry4.grid_forget()
  1461. radEntry5.grid_forget()
  1462. radEntry6.grid_forget()
  1463. radEntry7.grid_forget()
  1464. radEntry8.grid_forget()
  1465. radEntry9.grid_forget()
  1466. radEntry10.grid_forget()
  1467.  
  1468. def radButton4():
  1469. radEntry1.grid_forget()
  1470. radEntry2.grid_forget()
  1471. radEntry3.grid_forget()
  1472. radEntry4.grid(column=2, row=3)
  1473. radEntry5.grid_forget()
  1474. radEntry6.grid_forget()
  1475. radEntry7.grid_forget()
  1476. radEntry8.grid_forget()
  1477. radEntry9.grid_forget()
  1478. radEntry10.grid_forget()
  1479.  
  1480. def radButton5():
  1481. radEntry1.grid_forget()
  1482. radEntry2.grid_forget()
  1483. radEntry3.grid_forget()
  1484. radEntry4.grid_forget()
  1485. radEntry5.grid(column=2, row=4)
  1486. radEntry6.grid_forget()
  1487. radEntry7.grid_forget()
  1488. radEntry8.grid_forget()
  1489. radEntry9.grid_forget()
  1490. radEntry10.grid_forget()
  1491.  
  1492. def radButton6():
  1493. radEntry1.grid_forget()
  1494. radEntry2.grid_forget()
  1495. radEntry3.grid_forget()
  1496. radEntry4.grid_forget()
  1497. radEntry5.grid_forget()
  1498. radEntry6.grid(column=2, row=5)
  1499. radEntry7.grid_forget()
  1500. radEntry8.grid_forget()
  1501. radEntry9.grid_forget()
  1502. radEntry10.grid_forget()
  1503.  
  1504. def radButton7():
  1505. radEntry1.grid_forget()
  1506. radEntry2.grid_forget()
  1507. radEntry3.grid_forget()
  1508. radEntry4.grid_forget()
  1509. radEntry5.grid_forget()
  1510. radEntry6.grid_forget()
  1511. radEntry7.grid(column=2, row=6)
  1512. radEntry8.grid_forget()
  1513. radEntry9.grid_forget()
  1514. radEntry10.grid_forget()
  1515.  
  1516. def radButton8():
  1517. radEntry1.grid_forget()
  1518. radEntry2.grid_forget()
  1519. radEntry3.grid_forget()
  1520. radEntry4.grid_forget()
  1521. radEntry5.grid_forget()
  1522. radEntry6.grid_forget()
  1523. radEntry7.grid_forget()
  1524. radEntry8.grid(column=2, row=7)
  1525. radEntry9.grid_forget()
  1526. radEntry10.grid_forget()
  1527.  
  1528. def radButton9():
  1529. radEntry1.grid_forget()
  1530. radEntry2.grid_forget()
  1531. radEntry3.grid_forget()
  1532. radEntry4.grid_forget()
  1533. radEntry5.grid_forget()
  1534. radEntry6.grid_forget()
  1535. radEntry7.grid_forget()
  1536. radEntry8.grid_forget()
  1537. radEntry9.grid(column=2, row=8)
  1538. radEntry10.grid_forget()
  1539.  
  1540. def radButton10():
  1541. radEntry1.grid_forget()
  1542. radEntry2.grid_forget()
  1543. radEntry3.grid_forget()
  1544. radEntry4.grid_forget()
  1545. radEntry5.grid_forget()
  1546. radEntry6.grid_forget()
  1547. radEntry7.grid_forget()
  1548. radEntry8.grid_forget()
  1549. radEntry9.grid_forget()
  1550. radEntry10.grid(column=2, row=9)
  1551.  
  1552. def budgetingButtonEnter():
  1553.  
  1554. cursor.execute(''' SELECT foodbudget, educationbudget, groceriesbudget, fuelbudget, clothingbudget, transportbudget,
  1555. utilitiesbudget, healthbudget, insurancebudget, othersbudget FROM users WHERE username=?''', (GetLoginName,))
  1556. values = cursor.fetchone()
  1557.  
  1558. if selected.get():
  1559. if radEntry1.get() or radEntry2.get() or radEntry3.get() or radEntry4.get() or radEntry5.get() or radEntry6.get() or radEntry7.get() or radEntry8.get() or radEntry9.get() or radEntry10.get():
  1560. if str(radEntry1.get()).isdigit() or str(radEntry2.get()).isdigit() or str(radEntry3.get()).isdigit() or \
  1561. str(radEntry4.get()).isdigit() or str(radEntry5.get()).isdigit() or str(radEntry6.get()).isdigit() or str(radEntry7.get()).isdigit() \
  1562. or str(radEntry8.get()).isdigit() or str(radEntry9.get()).isdigit() or str(radEntry10.get()).isdigit():
  1563. if selected.get() == 1:
  1564. budgetInput = radEntry1.get()
  1565. iValue = values[0]
  1566. nValue = float(iValue) + float(budgetInput)
  1567. cursor.execute(''' UPDATE users SET foodbudget = ? WHERE username = ? ''', (nValue, GetLoginName,))
  1568. db.commit()
  1569. radEntry1.delete(0, END)
  1570. radEntry1.insert(0, "")
  1571. elif selected.get() == 2:
  1572. budgetInput = radEntry2.get()
  1573. iValue = values[1]
  1574. nValue = float(iValue) + float(budgetInput)
  1575. cursor.execute(''' UPDATE users SET educationbudget = ? WHERE username = ? ''',
  1576. (nValue, GetLoginName,))
  1577. db.commit()
  1578. radEntry2.delete(0, END)
  1579. radEntry2.insert(0, "")
  1580. elif selected.get() == 3:
  1581. budgetInput = radEntry3.get()
  1582. iValue = values[2]
  1583. nValue = float(iValue) + float(budgetInput)
  1584. cursor.execute(''' UPDATE users SET groceriesbudget = ? WHERE username = ? ''',
  1585. (nValue, GetLoginName,))
  1586. db.commit()
  1587. radEntry3.delete(0, END)
  1588. radEntry3.insert(0, "")
  1589. elif selected.get() == 4:
  1590. budgetInput = radEntry4.get()
  1591. iValue = values[3]
  1592. nValue = float(iValue) + float(budgetInput)
  1593. cursor.execute(''' UPDATE users SET fuelbudget = ? WHERE username = ? ''', (nValue, GetLoginName,))
  1594. db.commit()
  1595. radEntry4.delete(0, END)
  1596. radEntry4.insert(0, "")
  1597. elif selected.get() == 5:
  1598. budgetInput = radEntry5.get()
  1599. iValue = values[4]
  1600. nValue = float(iValue) + float(budgetInput)
  1601. cursor.execute(''' UPDATE users SET clothingbudget = ? WHERE username = ? ''',
  1602. (nValue, GetLoginName,))
  1603. db.commit()
  1604. radEntry5.delete(0, END)
  1605. radEntry5.insert(0, "")
  1606. elif selected.get() == 6:
  1607. budgetInput = radEntry6.get()
  1608. iValue = values[5]
  1609. nValue = float(iValue) + float(budgetInput)
  1610. cursor.execute(''' UPDATE users SET transportbudget = ? WHERE username = ? ''',
  1611. (nValue, GetLoginName,))
  1612. db.commit()
  1613. radEntry6.delete(0, END)
  1614. radEntry6.insert(0, "")
  1615. elif selected.get() == 7:
  1616. budgetInput = radEntry7.get()
  1617. iValue = values[6]
  1618. nValue = float(iValue) + float(budgetInput)
  1619. cursor.execute(''' UPDATE users SET utilitiesbudget = ? WHERE username = ? ''',
  1620. (nValue, GetLoginName,))
  1621. db.commit()
  1622. radEntry7.delete(0, END)
  1623. radEntry7.insert(0, "")
  1624. elif selected.get() == 8:
  1625. budgetInput = radEntry8.get()
  1626. iValue = values[7]
  1627. nValue = float(iValue) + float(budgetInput)
  1628. cursor.execute(''' UPDATE users SET healthbudget = ? WHERE username = ? ''',
  1629. (nValue, GetLoginName,))
  1630. db.commit()
  1631. radEntry8.delete(0, END)
  1632. radEntry8.insert(0, "")
  1633. elif selected.get() == 9:
  1634. budgetInput = radEntry9.get()
  1635. iValue = values[8]
  1636. nValue = float(iValue) + float(budgetInput)
  1637. cursor.execute(''' UPDATE users SET insurancebudget = ? WHERE username = ? ''',
  1638. (nValue, GetLoginName,))
  1639. db.commit()
  1640. radEntry9.delete(0, END)
  1641. radEntry9.insert(0, "")
  1642. elif selected.get() == 10:
  1643. budgetInput = radEntry10.get()
  1644. iValue = values[9]
  1645. nValue = float(iValue) + float(budgetInput)
  1646. cursor.execute(''' UPDATE users SET othersbudget = ? WHERE username = ? ''',
  1647. (nValue, GetLoginName,))
  1648. db.commit()
  1649. radEntry10.delete(0, END)
  1650. radEntry10.insert(0, "")
  1651. tkinter.messagebox.showinfo("Success", "Value successfully registered")
  1652.  
  1653. getFoodBudget = cursor.execute(''' SELECT foodbudget FROM users WHERE username = ?''',
  1654. (GetLoginName,)).fetchone()
  1655. foodbudgetlabel = Label(BudgetingFrame, text=getFoodBudget[0])
  1656. foodbudgetlabel.grid(row=0, column=0)
  1657.  
  1658. getEducationBudget = cursor.execute(''' SELECT educationbudget FROM users WHERE username = ? ''',
  1659. (GetLoginName,)).fetchone()
  1660. educationbudgetlabel = Label(BudgetingFrame, text=getEducationBudget[0])
  1661. educationbudgetlabel.grid(row=1, column=0)
  1662.  
  1663. getGroceriesBudget = cursor.execute(''' SELECT groceriesbudget FROM users WHERE username = ? ''',
  1664. (GetLoginName,)).fetchone()
  1665. groceriesbudgetlabel = Label(BudgetingFrame, text=getGroceriesBudget[0])
  1666. groceriesbudgetlabel.grid(row=2, column=0)
  1667.  
  1668. getFuelBudget = cursor.execute(''' SELECT fuelbudget FROM users WHERE username = ? ''',
  1669. (GetLoginName,)).fetchone()
  1670. fuelbudgetlabel = Label(BudgetingFrame, text=getFuelBudget[0])
  1671. fuelbudgetlabel.grid(row=3, column=0)
  1672.  
  1673. getClothingBudget = cursor.execute(''' SELECT clothingbudget FROM users WHERE username = ? ''',
  1674. (GetLoginName,)).fetchone()
  1675. clothingbudgetlabel = Label(BudgetingFrame, text=getClothingBudget[0])
  1676. clothingbudgetlabel.grid(row=4, column=0)
  1677.  
  1678. getTransportBudget = cursor.execute(''' SELECT transportbudget FROM users WHERE username = ? ''',
  1679. (GetLoginName,)).fetchone()
  1680. transportbudgetlabel = Label(BudgetingFrame, text=getTransportBudget[0])
  1681. transportbudgetlabel.grid(row=5, column=0)
  1682.  
  1683. getUtilitiesBudget = cursor.execute(''' SELECT utilitiesbudget FROM users WHERE username = ? ''',
  1684. (GetLoginName,)).fetchone()
  1685. utilitiesbudgetlabel = Label(BudgetingFrame, text=getUtilitiesBudget[0])
  1686. utilitiesbudgetlabel.grid(row=6, column=0)
  1687.  
  1688. getHealthBudget = cursor.execute(''' SELECT healthbudget FROM users WHERE username = ? ''',
  1689. (GetLoginName,)).fetchone()
  1690. healthbudgetlabel = Label(BudgetingFrame, text=getHealthBudget[0])
  1691. healthbudgetlabel.grid(row=7, column=0)
  1692.  
  1693. getInsuranceBudget = cursor.execute(''' SELECT insurancebudget FROM users WHERE username = ? ''',
  1694. (GetLoginName,)).fetchone()
  1695. insurancebudgetlabel = Label(BudgetingFrame, text=getInsuranceBudget[0])
  1696. insurancebudgetlabel.grid(row=8, column=0)
  1697.  
  1698. getOthersBudget = cursor.execute(''' SELECT othersbudget FROM users WHERE username = ? ''',
  1699. (GetLoginName,)).fetchone()
  1700. othersbudgetlabel = Label(BudgetingFrame, text=getOthersBudget[0])
  1701. othersbudgetlabel.grid(row=9, column=0)
  1702. else:
  1703. tkinter.messagebox.showerror("Error", "Enter a valid value")
  1704. else:
  1705. tkinter.messagebox.showerror("Error", "Enter a value")
  1706. else:
  1707. tkinter.messagebox.showerror("Error", "Select a category first")
  1708.  
  1709.  
  1710. selected = IntVar()
  1711.  
  1712. rad1 = Radiobutton(BudgetingFrame, text='Food', value=1, variable=selected, command=radButton1)
  1713.  
  1714. rad2 = Radiobutton(BudgetingFrame, text='Education', value=2, variable=selected, command=radButton2)
  1715.  
  1716. rad3 = Radiobutton(BudgetingFrame, text='Groceries', value=3, variable=selected, command=radButton3)
  1717.  
  1718. rad4 = Radiobutton(BudgetingFrame, text='Fuel', value=4, variable=selected, command=radButton4)
  1719.  
  1720. rad5 = Radiobutton(BudgetingFrame, text='Clothing', value=5, variable=selected, command=radButton5)
  1721.  
  1722. rad6 = Radiobutton(BudgetingFrame, text='Transport', value=6, variable=selected, command=radButton6)
  1723.  
  1724. rad7 = Radiobutton(BudgetingFrame, text='Utilities', value=7, variable=selected, command=radButton7)
  1725.  
  1726. rad8 = Radiobutton(BudgetingFrame, text='Health Care', value=8, variable=selected, command=radButton8)
  1727.  
  1728. rad9 = Radiobutton(BudgetingFrame, text='Insurance', value=9, variable=selected, command=radButton9)
  1729.  
  1730. rad10 = Radiobutton(BudgetingFrame, text='Others', value=10, variable=selected, command=radButton10)
  1731.  
  1732. radEntry1 = Entry(BudgetingFrame)
  1733.  
  1734. radEntry2 = Entry(BudgetingFrame)
  1735.  
  1736. radEntry3 = Entry(BudgetingFrame)
  1737.  
  1738. radEntry4 = Entry(BudgetingFrame)
  1739.  
  1740. radEntry5 = Entry(BudgetingFrame)
  1741.  
  1742. radEntry6 = Entry(BudgetingFrame)
  1743.  
  1744. radEntry7 = Entry(BudgetingFrame)
  1745.  
  1746. radEntry8 = Entry(BudgetingFrame)
  1747.  
  1748. radEntry9 = Entry(BudgetingFrame)
  1749.  
  1750. radEntry10 = Entry(BudgetingFrame)
  1751.  
  1752. btn1 = Button(BudgetingFrame, text="Enter", fg="blue", command=budgetingButtonEnter)
  1753.  
  1754. rad1.grid(column=1, row=0, sticky=W)
  1755.  
  1756. rad2.grid(column=1, row=1, sticky=W)
  1757.  
  1758. rad3.grid(column=1, row=2, sticky=W)
  1759.  
  1760. rad4.grid(column=1, row=3, sticky=W)
  1761.  
  1762. rad5.grid(column=1, row=4, sticky=W)
  1763.  
  1764. rad6.grid(column=1, row=5, sticky=W)
  1765.  
  1766. rad7.grid(column=1, row=6, sticky=W)
  1767.  
  1768. rad8.grid(column=1, row=7, sticky=W)
  1769.  
  1770. rad9.grid(column=1, row=8, sticky=W)
  1771.  
  1772. rad10.grid(column=1, row=9, sticky=W)
  1773.  
  1774. radEntry1.grid_forget()
  1775.  
  1776. radEntry2.grid_forget()
  1777.  
  1778. radEntry3.grid_forget()
  1779.  
  1780. radEntry4.grid_forget()
  1781.  
  1782. radEntry5.grid_forget()
  1783.  
  1784. radEntry6.grid_forget()
  1785.  
  1786. radEntry7.grid_forget()
  1787.  
  1788. radEntry8.grid_forget()
  1789.  
  1790. radEntry9.grid_forget()
  1791.  
  1792. radEntry10.grid_forget()
  1793.  
  1794. btn1.grid(columnspan=3, row=10)
  1795.  
  1796. btn2 = Button(BudgetingFrame, text="Back", fg="blue", command=backToMainUI)
  1797. btn2.grid(columnspan=3, row=11)
  1798.  
  1799. '''
  1800.  
  1801. END BUDGETING FRAME
  1802.  
  1803. '''
  1804. root.mainloop()
Add Comment
Please, Sign In to add comment