Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f4e9393

Browse files
Updating the main.py file
Added the database and implemented the script with as a GUI application
1 parent 3de0844 commit f4e9393

File tree

1 file changed

+103
-39
lines changed

1 file changed

+103
-39
lines changed

‎Health_Log_Book/main.py‎

Lines changed: 103 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,110 @@
1-
# It is a health management system
2-
# Consists of food and exercise log table
3-
# Has the fascility both to enter a log and to retrieve the log
4-
# Helps the user to inspect his/her health
5-
61
# importing the modules
2+
import tkinter as tk
3+
from tkinter import messagebox
74
import datetime
5+
import database
6+
87

98
# creating a function to return date and time
109
def getdate():
1110
return datetime.datetime.now()
1211

13-
# defining a function to take the inputs from the user and store the input data in a text file
14-
def take():
15-
x = int(input("enter 1 for exercise and 2 for food"))
16-
if x==1:
17-
val = input("enter each exersise separated with commas\n")
18-
with open("user-exercise.txt","a") as f:
19-
f.write(str([str(getdate())]) + ":- " + val + "\n")
20-
print("successfully written")
21-
elif x==2:
22-
val = input("enter each food separated with commas\n")
23-
with open("user-food.txt", "a") as f:
24-
f.write(str([str(getdate())]) + ":- " + val + "\n")
25-
print("successfully written")
26-
27-
# defining a function to retrieve the data from the text file
28-
def retrieve():
29-
x = int(input("enter 1 for exercise and 2 for food"))
30-
if x == 1:
31-
with open("user-exercise.txt") as f:
32-
for i in f:
33-
print(i,end=" ")
34-
elif x == 2:
35-
with open("user-food.txt") as f:
36-
for i in f:
37-
print(i, end=" ")
38-
39-
# Testing code
40-
print("Health log book: ")
41-
a = int(input("press 1 for log and 2 for retrieve"))
42-
43-
if a==1:
44-
take()
45-
else:
46-
retrieve()
12+
13+
# Creating the connection
14+
connection = database.connect()
15+
database.create_table1(connection)
16+
database.create_table2(connection)
17+
18+
19+
def store_exercise():
20+
date = getdate()
21+
data = exercise_entry.get("1.0", 'end-1c')
22+
if data != "":
23+
exercise_entry.delete("1.0", "end")
24+
database.add_exercise(connection, date, data)
25+
messagebox.showinfo("Success", "Log is inserted")
26+
else:
27+
messagebox.showerror("Error", "Enter Something")
28+
29+
30+
def store_food():
31+
date = getdate()
32+
data = food_entry.get("1.0", "end-1c")
33+
if data != "":
34+
food_entry.delete("1.0", "end")
35+
database.add_food(connection, date, data)
36+
messagebox.showinfo("Success", "Log is inserted")
37+
else:
38+
messagebox.showerror("Error", "Enter Something")
39+
40+
41+
def show_exercise():
42+
con = database.connect()
43+
cor = con.cursor()
44+
cor.execute('''SELECT * from exercise''')
45+
rows = cor.fetchall()
46+
47+
for row in rows:
48+
print(row)
49+
50+
51+
def show_food():
52+
con = database.connect()
53+
cor = con.cursor()
54+
cor.execute('''SELECT * from food''')
55+
rows = cor.fetchall()
56+
57+
for row in rows:
58+
print(row)
59+
60+
61+
def delete_exercise_log():
62+
messagebox.showinfo("Delete", "The Exercise Log is deleted")
63+
database.delete_exercise(connection)
64+
65+
66+
def delete_food_log():
67+
messagebox.showinfo("Delete", "The Food Log is deleted")
68+
database.delete_food(connection)
69+
70+
71+
# Making the GUI
72+
root = tk.Tk()
73+
74+
root.title("main")
75+
root.geometry("500x500")
76+
77+
heading = tk.Label(root, text="Health Log book", font=('Helvetica', 18, 'bold'))
78+
heading.pack()
79+
80+
exercise_heading = tk.Label(root, text=" 1) Enter each exercise separated with commas", font=('Helvetica', 11, 'bold'))
81+
exercise_heading.place(x=30, y=40)
82+
83+
exercise_entry = tk.Text(root, height=5, width=42)
84+
exercise_entry.pack(pady=30)
85+
86+
exercise_submit = tk.Button(root, text="Submit", command=store_exercise)
87+
exercise_submit.place(x=210, y=160)
88+
89+
food_heading = tk.Label(root, text="2) Enter each food separated with commas", font=('Helvetica', 11, 'bold'))
90+
food_heading.place(x=30, y=200)
91+
92+
food_entry = tk.Text(root, height=5, width=42)
93+
food_entry.pack(pady=40)
94+
95+
food_submit = tk.Button(root, text="Submit", command=store_food)
96+
food_submit.place(x=210, y=330)
97+
98+
retrieve_exercise = tk.Button(root, text="Show Exercise Log", command=show_exercise)
99+
retrieve_exercise.place(x=50, y=400)
100+
101+
retrieve_food = tk.Button(root, text="Show food Log", command=show_food)
102+
retrieve_food.place(x=300, y=400)
103+
104+
delete_exercise = tk.Button(root, text="Delete Exercise Log", command=delete_exercise_log)
105+
delete_exercise.place(x=50, y=450)
106+
107+
delete_food = tk.Button(root, text="Delete food Log", command=delete_food_log)
108+
delete_food.place(x=300, y=450)
109+
110+
root.mainloop()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /