Skip to content

Commit 3f0dd7a

Browse files
Merge pull request avinashkranjan#830 from anuragmukherjee2001/health_log_book
Health log book
2 parents dc12e6a + 86f195c commit 3f0dd7a

File tree

3 files changed

+271
-0
lines changed

3 files changed

+271
-0
lines changed

Health_Log_Book/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Health log book
2+
3+
### Details of the script:-
4+
The script will contain the daily records of food and workouts of a person. The user will only enter the name of the foods, it will be stored in a text file with corresponding date and time. Similarly, the user will enter the types of workout at their workout time. The workouts will be stored in a text file with date and time. The user can also retrieve the data whenever they want to see.
5+
6+
### Advantages of the script:-
7+
This script will help the user to maintain his/her health, as it is keeping a daily track of their diet and workout style. At the end of the day, or at the end of the week, he/she can analyze the data and can lead a healthy and fit lifestyle.
8+
9+
### Modules Used:-
10+
11+
1) datetime
12+
2) sqlite3
13+
3) tkinter
14+
4) messagebox
15+
16+
### Image of the GUI:-
17+
![Screenshot from 2021-04-09 12-52-27](https://user-images.githubusercontent.com/62845847/114144009-7a0cb600-9932-11eb-8f47-8fcc541229e7.png)
18+

Health_Log_Book/database.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Importing the module
2+
import sqlite3
3+
4+
# Writing the Query for creating the exercise table
5+
Create_exercise_table = """
6+
CREATE TABLE IF NOT EXISTS exercise
7+
(
8+
id INTEGER PRIMARY KEY,
9+
date TEXT,
10+
data TEXT
11+
);
12+
"""
13+
14+
# Writing the query for inserting values into exercise table
15+
insert_exercise = """
16+
INSERT INTO exercise (date, data) VALUES (?, ?);
17+
"""
18+
19+
# Writing the query for inserting values into food table
20+
insert_food = """
21+
INSERT INTO food (date, data) VALUES (?, ?);
22+
"""
23+
24+
# Writing the query for creating the food table
25+
Create_food_table = """
26+
CREATE TABLE IF NOT EXISTS food
27+
(
28+
id INTEGER PRIMARY KEY,
29+
date TEXT,
30+
data TEXT
31+
);
32+
"""
33+
34+
# Writing the query for deleting the exercise table
35+
delete_exercise_table = """
36+
DROP TABLE exercise
37+
"""
38+
39+
# Writing the query for deleting the food table
40+
delete_food_table = """
41+
DROP TABLE food
42+
"""
43+
44+
# defining functions for different queries
45+
46+
def connect():
47+
connection = sqlite3.connect("data.db")
48+
return connection
49+
50+
51+
def create_table1(connection):
52+
with connection:
53+
connection.execute(Create_exercise_table)
54+
55+
56+
def create_table2(connection):
57+
with connection:
58+
connection.execute(Create_food_table)
59+
60+
61+
def add_exercise(connection, date, data):
62+
with connection:
63+
connection.execute(insert_exercise, (date, data))
64+
65+
66+
def add_food(connection, date, data):
67+
with connection:
68+
connection.execute(insert_food, (date, data))
69+
70+
71+
def delete_exercise(connection):
72+
with connection:
73+
connection.execute(delete_exercise_table)
74+
75+
76+
def delete_food(connection):
77+
with connection:
78+
connection.execute(delete_food_table)

Health_Log_Book/main.py

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
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

Comments
 (0)