|
| 1 | +# importing the modules |
| 2 | +import tkinter as tk |
| 3 | +from tkinter import messagebox |
| 4 | +from tkinter import ttk |
| 5 | +import datetime |
| 6 | +import database |
| 7 | + |
| 8 | + |
| 9 | +# creating a function to return date and time |
| 10 | +def getdate(): |
| 11 | + return datetime.datetime.now() |
| 12 | + |
| 13 | + |
| 14 | +# Creating the connection |
| 15 | +connection = database.connect() |
| 16 | +database.create_table1(connection) |
| 17 | +database.create_table2(connection) |
| 18 | + |
| 19 | + |
| 20 | +def store_exercise(): |
| 21 | + date = getdate() |
| 22 | + data = exercise_entry.get("1.0", 'end-1c') |
| 23 | + if data != "": |
| 24 | + exercise_entry.delete("1.0", "end") |
| 25 | + database.add_exercise(connection, date, data) |
| 26 | + messagebox.showinfo("Success", "Log is inserted") |
| 27 | + else: |
| 28 | + messagebox.showerror("Error", "Enter Something") |
| 29 | + |
| 30 | + |
| 31 | +def store_food(): |
| 32 | + date = getdate() |
| 33 | + data = food_entry.get("1.0", "end-1c") |
| 34 | + if data != "": |
| 35 | + food_entry.delete("1.0", "end") |
| 36 | + database.add_food(connection, date, data) |
| 37 | + messagebox.showinfo("Success", "Log is inserted") |
| 38 | + else: |
| 39 | + messagebox.showerror("Error", "Enter Something") |
| 40 | + |
| 41 | + |
| 42 | +def show_exercise(): |
| 43 | + con = database.connect() |
| 44 | + cor = con.cursor() |
| 45 | + try: |
| 46 | + cor.execute('''SELECT * from exercise''') |
| 47 | + rows = cor.fetchall() |
| 48 | + new = tk.Tk() |
| 49 | + new.title("Exercise Log") |
| 50 | + new.geometry("650x500") |
| 51 | + |
| 52 | + frm = tk.Frame(new) |
| 53 | + frm.pack(side=tk.LEFT, padx=20) |
| 54 | + |
| 55 | + tv = ttk.Treeview(frm, selectmode='browse') |
| 56 | + tv.pack() |
| 57 | + verscrlbar = ttk.Scrollbar(new, |
| 58 | + orient="vertical", |
| 59 | + command=tv.yview) |
| 60 | + |
| 61 | + verscrlbar.pack(side='right', fill='x') |
| 62 | + |
| 63 | + tv.configure(xscrollcommand=verscrlbar.set) |
| 64 | + |
| 65 | + tv["columns"] = ("1", "2", "3") |
| 66 | + tv['show'] = 'headings' |
| 67 | + |
| 68 | + tv.column("1", width=50, anchor='c') |
| 69 | + tv.column("2", width=250, anchor='c') |
| 70 | + tv.column("3", width=400, anchor='w') |
| 71 | + |
| 72 | + tv.heading("1", text="Sl.No") |
| 73 | + tv.heading("2", text="Time") |
| 74 | + tv.heading("3", text="Data") |
| 75 | + |
| 76 | + for i in rows: |
| 77 | + tv.insert("", "end", values=i) |
| 78 | + |
| 79 | + new.mainloop() |
| 80 | + except: |
| 81 | + messagebox.showerror("Error", "Some Error Occurred") |
| 82 | + |
| 83 | + |
| 84 | +def show_food(): |
| 85 | + con = database.connect() |
| 86 | + cor = con.cursor() |
| 87 | + try: |
| 88 | + cor.execute('''SELECT * from food''') |
| 89 | + rows = cor.fetchall() |
| 90 | + new = tk.Tk() |
| 91 | + new.title("Food Log") |
| 92 | + new.geometry("650x500") |
| 93 | + |
| 94 | + frm = tk.Frame(new) |
| 95 | + frm.pack(side=tk.LEFT, padx=20) |
| 96 | + |
| 97 | + tv = ttk.Treeview(frm, selectmode='browse') |
| 98 | + tv.pack() |
| 99 | + verscrlbar = ttk.Scrollbar(new, |
| 100 | + orient="vertical", |
| 101 | + command=tv.yview) |
| 102 | + |
| 103 | + verscrlbar.pack(side='right', fill='x') |
| 104 | + |
| 105 | + tv.configure(xscrollcommand=verscrlbar.set) |
| 106 | + |
| 107 | + tv["columns"] = ("1", "2", "3") |
| 108 | + tv['show'] = 'headings' |
| 109 | + |
| 110 | + tv.column("1", width=50, anchor='c') |
| 111 | + tv.column("2", width=250, anchor='c') |
| 112 | + tv.column("3", width=400, anchor='w') |
| 113 | + |
| 114 | + tv.heading("1", text="Sl.No") |
| 115 | + tv.heading("2", text="Time") |
| 116 | + tv.heading("3", text="Data") |
| 117 | + |
| 118 | + for i in rows: |
| 119 | + tv.insert("", "end", values=i) |
| 120 | + |
| 121 | + new.mainloop() |
| 122 | + except: |
| 123 | + messagebox.showerror("Error", "Some Error Occurred") |
| 124 | + |
| 125 | + |
| 126 | +def delete_exercise_log(): |
| 127 | + messagebox.showinfo("Delete", "The Exercise Log is deleted") |
| 128 | + database.delete_exercise(connection) |
| 129 | + |
| 130 | + |
| 131 | +def delete_food_log(): |
| 132 | + messagebox.showinfo("Delete", "The Food Log is deleted") |
| 133 | + database.delete_food(connection) |
| 134 | + |
| 135 | + |
| 136 | +# Making the GUI |
| 137 | +root = tk.Tk() |
| 138 | + |
| 139 | +root.title("main") |
| 140 | +root.geometry("500x500") |
| 141 | + |
| 142 | +heading = tk.Label(root, text="Health Log book", font=('Helvetica', 18, 'bold')) |
| 143 | +heading.pack() |
| 144 | + |
| 145 | +exercise_heading = tk.Label(root, text=" 1) Enter each exercise separated with commas", font=('Helvetica', 11, 'bold')) |
| 146 | +exercise_heading.place(x=30, y=40) |
| 147 | + |
| 148 | +exercise_entry = tk.Text(root, height=5, width=42) |
| 149 | +exercise_entry.pack(pady=30) |
| 150 | + |
| 151 | +exercise_submit = tk.Button(root, text="Submit", command=store_exercise) |
| 152 | +exercise_submit.place(x=210, y=160) |
| 153 | + |
| 154 | +food_heading = tk.Label(root, text="2) Enter each food separated with commas", font=('Helvetica', 11, 'bold')) |
| 155 | +food_heading.place(x=30, y=200) |
| 156 | + |
| 157 | +food_entry = tk.Text(root, height=5, width=42) |
| 158 | +food_entry.pack(pady=40) |
| 159 | + |
| 160 | +food_submit = tk.Button(root, text="Submit", command=store_food) |
| 161 | +food_submit.place(x=210, y=330) |
| 162 | + |
| 163 | +retrieve_exercise = tk.Button(root, text="Show Exercise Log", command=show_exercise) |
| 164 | +retrieve_exercise.place(x=50, y=400) |
| 165 | + |
| 166 | +retrieve_food = tk.Button(root, text="Show food Log", command=show_food) |
| 167 | +retrieve_food.place(x=300, y=400) |
| 168 | + |
| 169 | +delete_exercise = tk.Button(root, text="Delete Exercise Log", command=delete_exercise_log) |
| 170 | +delete_exercise.place(x=50, y=450) |
| 171 | + |
| 172 | +delete_food = tk.Button(root, text="Delete food Log", command=delete_food_log) |
| 173 | +delete_food.place(x=300, y=450) |
| 174 | + |
| 175 | +root.mainloop() |
0 commit comments