|
| 1 | +import db |
| 2 | +import tkinter as tk |
| 3 | +from tkinter.ttk import Button, Frame, Entry, Label |
| 4 | + |
| 5 | +LARGE_FONT = ("Verdana", 32) |
| 6 | + |
| 7 | + |
| 8 | +class ExpenseManager: |
| 9 | + def __init__(self, master): |
| 10 | + self.frame = Frame(master) |
| 11 | + self.frame.pack() |
| 12 | + self.main_window() |
| 13 | + |
| 14 | + # display function calls for database update deletion and listing added or deleted# |
| 15 | + def added(self, boxaile): |
| 16 | + myLabel = Label(boxaile, text="The value has been inserted") |
| 17 | + myLabel.grid(row=4, column=0) |
| 18 | + |
| 19 | + def delete(self, boxaile): |
| 20 | + myLabel = Label(boxaile, text="The value was deleted") |
| 21 | + myLabel.grid(row=4, column=0) |
| 22 | + |
| 23 | + def display_all(self, database): |
| 24 | + select_all = database |
| 25 | + return select_all |
| 26 | + |
| 27 | + def insert(self, database, val1, val2, val3): |
| 28 | + goods = val1.get() |
| 29 | + price = val2.get() |
| 30 | + date = val3.get() |
| 31 | + insertion = database(goods, price, date) |
| 32 | + return insertion |
| 33 | + |
| 34 | + def find_expense(self, database, val1, val2): |
| 35 | + goods = val1.get() |
| 36 | + price = val2.get() |
| 37 | + find = database(goods, price) |
| 38 | + return find |
| 39 | + |
| 40 | + def delete_expense(self, database, val1, val2): |
| 41 | + goods = val1.get() |
| 42 | + price = val2.get() |
| 43 | + delete = database(goods, price) |
| 44 | + return delete |
| 45 | + |
| 46 | + # MAIN WINDOW |
| 47 | + def main_window(self): |
| 48 | + button1 = Button(self.frame, text="Groceries expenses", command=self.groceries) |
| 49 | + button1.pack() |
| 50 | + |
| 51 | + button2 = Button(self.frame, text="Household expenses", command=self.household) |
| 52 | + button2.pack() |
| 53 | + |
| 54 | + button3 = Button(self.frame, text="Entertainment expenses", command=self.entertainment) |
| 55 | + button3.pack() |
| 56 | + |
| 57 | + button4 = Button(self.frame, text="Other expenses", command=self.other) |
| 58 | + button4.pack() |
| 59 | + |
| 60 | + button5 = Button(self.frame, text="EXIT", command=exit) |
| 61 | + button5.pack() |
| 62 | + |
| 63 | + # INSERT VALUES |
| 64 | + def groceries(self): |
| 65 | + top = tk.Toplevel(self.frame) |
| 66 | + top.title('Groceries expenses') |
| 67 | + Label(top, text="Name of good").grid(row=1, column=0, sticky=tk.W, pady=2) |
| 68 | + Label(top, text="Price").grid(row=2, column=0, sticky=tk.W, pady=2) |
| 69 | + Label(top, text="Date of purchase").grid(row=3, column=0, sticky=tk.W, pady=2) |
| 70 | + |
| 71 | + e1 = Entry(top) |
| 72 | + e1.grid(row=1, column=1, sticky=tk.W, pady=2) |
| 73 | + e2 = Entry(top) |
| 74 | + e2.grid(row=2, column=1, sticky=tk.W, pady=2) |
| 75 | + e3 = Entry(top) |
| 76 | + e3.grid(row=3, column=1, sticky=tk.W, pady=2) |
| 77 | + |
| 78 | + text = tk.Text(top, width=40, height=10) |
| 79 | + text.grid(row=5, column=1, columnspan=2) |
| 80 | + |
| 81 | + # BUTTONS |
| 82 | + |
| 83 | + B1 = Button(top, text="Insert Values", command=lambda: (self.insert(db.insert_groceries, e1, e2, e3), |
| 84 | + self.added(top))) |
| 85 | + B1.grid(row=1, column=2) |
| 86 | + |
| 87 | + B2 = Button(top, text="Select All", command=lambda: (text.delete(1.0, tk.END), |
| 88 | + text.insert(tk.END, self.display_all(db.select_all_groceries())))) |
| 89 | + B2.grid(row=2, column=2) |
| 90 | + |
| 91 | + B3 = Button(top, text="Find value", command=lambda: (text.delete(1.0, tk.END), |
| 92 | + text.insert(tk.END, self.find_expense(db.select_grocery, e1, e2)))) |
| 93 | + B3.grid(row=2, column=3) |
| 94 | + |
| 95 | + B3 = Button(top, text="Delete expense", command=lambda: (self.delete_expense(db.delete_grocery, e1, e2), |
| 96 | + self.delete(top))) |
| 97 | + B3.grid(row=4, column=2) |
| 98 | + |
| 99 | + B5 = Button(top, text="Exit", command=exit) |
| 100 | + B5.grid(row=4, column=3) |
| 101 | + |
| 102 | + def household(self): |
| 103 | + top = tk.Toplevel(self.frame) |
| 104 | + top.title('Household expenses') |
| 105 | + Label(top, text="Name of good").grid(row=1, column=0, sticky=tk.W, pady=2) |
| 106 | + Label(top, text="Price").grid(row=2, column=0, sticky=tk.W, pady=2) |
| 107 | + Label(top, text="Date of purchase").grid(row=3, column=0, sticky=tk.W, pady=2) |
| 108 | + |
| 109 | + e1 = Entry(top) |
| 110 | + e1.grid(row=1, column=1, sticky=tk.W, pady=2) |
| 111 | + e2 = Entry(top) |
| 112 | + e2.grid(row=2, column=1, sticky=tk.W, pady=2) |
| 113 | + e3 = Entry(top) |
| 114 | + e3.grid(row=3, column=1, sticky=tk.W, pady=2) |
| 115 | + |
| 116 | + text = tk.Text(top, width=40, height=10) |
| 117 | + text.grid(row=5, column=1, columnspan=2) |
| 118 | + |
| 119 | + # BUTTONS### |
| 120 | + |
| 121 | + B1 = Button(top, text="Insert Values", |
| 122 | + command=lambda: (self.insert(db.insert_household, e1, e2, e3), self.added(top))) |
| 123 | + B1.grid(row=1, column=2) |
| 124 | + |
| 125 | + B2 = Button(top, text="Select All", command=lambda: (text.delete(1.0, tk.END), |
| 126 | + text.insert(tk.END, self.display_all(db.select_all_household())))) |
| 127 | + B2.grid(row=2, column=2) |
| 128 | + |
| 129 | + B3 = Button(top, text="Find value", command=lambda: (text.delete(1.0, tk.END), |
| 130 | + text.insert(tk.END, self.find_expense(db.select_household, e1, e2)))) |
| 131 | + B3.grid(row=2, column=3) |
| 132 | + |
| 133 | + B3 = Button(top, text="Delete expense", |
| 134 | + command=lambda: (self.delete_expense(db.delete_household, e1, e2), self.delete(top))) |
| 135 | + B3.grid(row=4, column=2) |
| 136 | + |
| 137 | + B5 = Button(top, text="Exit", command=exit) |
| 138 | + B5.grid(row=4, column=3) |
| 139 | + |
| 140 | + def entertainment(self): |
| 141 | + top = tk.Toplevel(self.frame) |
| 142 | + top.title('Entertainment expenses') |
| 143 | + Label(top, text="Name of good").grid(row=1, column=0, sticky=tk.W, pady=2) |
| 144 | + Label(top, text="Price").grid(row=2, column=0, sticky=tk.W, pady=2) |
| 145 | + Label(top, text="Date of purchase").grid(row=3, column=0, sticky=tk.W, pady=2) |
| 146 | + |
| 147 | + e1 = Entry(top) |
| 148 | + e1.grid(row=1, column=1, sticky=tk.W, pady=2) |
| 149 | + e2 = Entry(top) |
| 150 | + e2.grid(row=2, column=1, sticky=tk.W, pady=2) |
| 151 | + e3 = Entry(top) |
| 152 | + e3.grid(row=3, column=1, sticky=tk.W, pady=2) |
| 153 | + |
| 154 | + text = tk.Text(top, width=40, height=10) |
| 155 | + text.grid(row=5, column=1, columnspan=2) |
| 156 | + |
| 157 | + # BUTTONS |
| 158 | + |
| 159 | + B1 = Button(top, text="Insert Values", |
| 160 | + command=lambda: (self.insert(db.insert_entertrainment, e1, e2, e3), self.added(top))) |
| 161 | + B1.grid(row=1, column=2) |
| 162 | + |
| 163 | + B2 = Button(top, text="Select All", command=lambda: (text.delete(1.0, tk.END), |
| 164 | + text.insert(tk.END, self.display_all(db.select_all_entertrainment())))) |
| 165 | + B2.grid(row=2, column=2) |
| 166 | + |
| 167 | + B3 = Button(top, text="Find value", command=lambda: (text.delete(1.0, tk.END), |
| 168 | + text.insert(tk.END, self.find_expense(db.select_entertainment, e1, e2)))) |
| 169 | + B3.grid(row=2, column=3) |
| 170 | + |
| 171 | + B3 = Button(top, text="Delete expense", |
| 172 | + command=lambda: (self.delete_expense(db.delete_entertainment, e1, e2), self.delete(top))) |
| 173 | + B3.grid(row=4, column=2) |
| 174 | + |
| 175 | + B5 = Button(top, text="Exit", command=exit) |
| 176 | + B5.grid(row=4, column=3) |
| 177 | + |
| 178 | + def other(self): |
| 179 | + top = tk.Toplevel(self.frame) |
| 180 | + top.title('Entertainment expenses') |
| 181 | + Label(top, text="Name of good").grid(row=1, column=0, sticky=tk.W, pady=2) |
| 182 | + Label(top, text="Price").grid(row=2, column=0, sticky=tk.W, pady=2) |
| 183 | + Label(top, text="Date of purchase").grid(row=3, column=0, sticky=tk.W, pady=2) |
| 184 | + |
| 185 | + e1 = Entry(top) |
| 186 | + e1.grid(row=1, column=1, sticky=tk.W, pady=2) |
| 187 | + e2 = Entry(top) |
| 188 | + e2.grid(row=2, column=1, sticky=tk.W, pady=2) |
| 189 | + e3 = Entry(top) |
| 190 | + e3.grid(row=3, column=1, sticky=tk.W, pady=2) |
| 191 | + |
| 192 | + text = tk.Text(top, width=40, height=10) |
| 193 | + text.grid(row=5, column=1, columnspan=2) |
| 194 | + |
| 195 | + # BUTTONS### |
| 196 | + |
| 197 | + B1 = Button(top, text="Insert Values", |
| 198 | + command=lambda: (self.insert(db.insert_other, e1, e2, e3), self.added(top))) |
| 199 | + B1.grid(row=1, column=2) |
| 200 | + |
| 201 | + B2 = Button(top, text="Select All", command=lambda: ( |
| 202 | + text.delete(1.0, tk.END), text.insert(tk.END, self.display_all(db.select_all_other())))) |
| 203 | + B2.grid(row=2, column=2) |
| 204 | + |
| 205 | + B3 = Button(top, text="Find value", command=lambda: ( |
| 206 | + text.delete(1.0, tk.END), text.insert(tk.END, self.find_expense(db.select_other, e1, e2)))) |
| 207 | + B3.grid(row=2, column=3) |
| 208 | + |
| 209 | + B3 = Button(top, text="Delete expense", |
| 210 | + command=lambda: (self.delete_expense(db.delete_other, e1, e2), self.delete(top))) |
| 211 | + B3.grid(row=4, column=2) |
| 212 | + |
| 213 | + B5 = Button(top, text="Exit", command=exit) |
| 214 | + B5.grid(row=4, column=3) |
| 215 | + |
| 216 | + |
| 217 | +def main(): |
| 218 | + # db.create_tables(connection) |
| 219 | + root = tk.Tk() |
| 220 | + root.geometry('600x500') |
| 221 | + root.title("Expense Manager") |
| 222 | + ExpenseManager(root) |
| 223 | + root.mainloop() |
| 224 | + |
| 225 | + |
| 226 | +main() |
0 commit comments