Advertisement
Guest User

Codee

a guest
May 24th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.63 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import *
  3. from tkinter.scrolledtext import ScrolledText
  4.  
  5. root = Tk()
  6. root.geometry("1600x1000+0+0")
  7. root.title("Ultimate Fitness Calculator")
  8. root.configure(bg='darkslategray')
  9. lbl_title = tk.Label(root,text="Welcome to the Ultimate Fitness Calculator by Cameron Su.", fg="white", bg = 'darkslategray')
  10. lbl_title.pack()
  11.  
  12. #==================================Setting the Frame=======================================
  13.  
  14. Tops = Frame(root, width=1600, height=50, bg="darkslategray", relief=SUNKEN)
  15. Tops.pack(side=TOP)
  16.  
  17. f1 = Frame(root, width=1600, height=900, bg="darkslategray", relief=SUNKEN)
  18. f1.pack(side=LEFT)
  19.  
  20.  
  21. #==================================System Information=======================================
  22.  
  23. lblInfo = Label(Tops, font=('Gill Sans', 50), text="Ultimate Fitness Calculator", fg="white",bg="darkslategray", bd=10, anchor='w').grid(row=0, column=0)
  24.  
  25. lblInfo = Label(Tops, font=('Gill Sans', 20), text="This multifunctional program calculates Basal Metabolic Rate, Total Daily Energy Expenditures \n and breaks down the amount of macronutrients needed to reach your fitness goals.", fg="white",bg="darkslategray",
  26. bd=10, anchor='w').grid(row=1, column=0)
  27.  
  28. #==================================Question 1===========================================
  29.  
  30. def Q1a_HeightCM():
  31. H = (float(Height_CM.get()))
  32.  
  33. return float(H)
  34.  
  35. def Q1b_WeightKG():
  36. W = (float(Weight_KG.get()))
  37.  
  38. return float(W)
  39.  
  40. def Q1c_Age():
  41. A = (float(Age.get()))
  42.  
  43. return float(A)
  44.  
  45. def Q1d_Gender():
  46. global H
  47. global W
  48. global A
  49.  
  50. MorF = (str(Gender.get()))
  51.  
  52. if MorF.upper() == 'M':
  53. BMR = (66 + (13.7*float(W)) + (5*float(H)) - (6.8*float(A)))
  54.  
  55. return BMR
  56.  
  57. elif MorF.upper() == 'F':
  58. BMR = (655 + (9.6*float(W)) + (1.8*float(H)) - (4.7*float(A)))
  59.  
  60. return BMR
  61.  
  62. def Q2_Lifestyle():
  63. global BMR
  64.  
  65. L = (str(Lifestyle.get()))
  66.  
  67. if L.upper() == 'A':
  68. TDEE = 1.2*float(BMR)
  69. return TDEE
  70.  
  71. elif L.upper() == 'B':
  72. TDEE = 1.375*float(BMR)
  73. return TDEE
  74.  
  75. elif L.upper() == 'C':
  76. TDEE = 1.55*float(BMR)
  77. return TDEE
  78.  
  79. elif L.upper() == 'D':
  80. TDEE = 1.725*float(BMR)
  81. return TDEE
  82.  
  83. elif L.upper() == 'E':
  84. TDEE = 1.9*float(BMR)
  85. return TDEE
  86.  
  87.  
  88. def Q3_Goal():
  89.  
  90. global TDEE
  91.  
  92. G = (str(Goal.get()))
  93.  
  94. if G.upper() == 'A':
  95. #ODC = Optimum Daily Calories
  96. ODC = ((float*TDEE) - 500)
  97. return ODC
  98.  
  99. Protein = 1.65*float(W)
  100.  
  101. return Protein
  102.  
  103. Carbs = 5*float(W)
  104. return Carbs
  105.  
  106. Fat = 0.88*float(W)
  107. return Fat
  108.  
  109. elif G.upper() == 'B':
  110. ODC = ((float*TDEE) + 500)
  111. return ODC
  112.  
  113. Protein = 2.2*float(W)
  114.  
  115. return Protein
  116.  
  117. Carbs = 7.5*float(W)
  118. return Carbs
  119.  
  120. Fat = 0.77*float(W)
  121. return Fat
  122.  
  123. elif G.upper() == 'C':
  124. ODC = float(TDEE)
  125. return ODC
  126.  
  127. Protein = 2.75*float(W)
  128.  
  129. return Protein
  130.  
  131. Carbs = 10*float(W)
  132. return Carbs
  133.  
  134. Fat = 0.66*float(W)
  135. return Fat
  136.  
  137. #--------------Functions for Buttons--------------
  138.  
  139. def Calculate():
  140. global BMR
  141. global TDEE
  142. global ODC
  143. global Protein
  144. global Carbs
  145. global Fat
  146. Q1a_HeightCM()
  147. Q1b_WeightKG()
  148. Q1c_Age()
  149. Q1d_Gender()
  150. Q2_Lifestyle()
  151. Q3_Goal()
  152.  
  153. FinalBMR.set(BMR)
  154. FinalTDEE.set(TDEE)
  155. FinalODC.set(ODC)
  156. FinalProtein.set(Protein)
  157. FinalCarbs.set(Carbs)
  158. FinalFat.set(Fat)
  159.  
  160.  
  161. def Reset():
  162. Height_CM.set("")
  163. Weight_KG.set("")
  164. Age.set("")
  165. Gender.set("")
  166.  
  167. Lifestyle.set("")
  168. Goal.set("")
  169.  
  170. FinalBMR.set("")
  171. FinalTDEE.set("")
  172. FinalODC.set("")
  173. FinalProtein.set("")
  174. FinalCarbs.set("")
  175. FinalFat.set("")
  176.  
  177. txtFAQ.delete('1.0', 'end')
  178.  
  179. def Exit():
  180. root.destroy()
  181.  
  182. txtFAQ = ScrolledText(f1,font=('Gill Sans',23),bd=2,insertwidth=4, width=34, height=14,bg='DarkOliveGreen4', relief=FLAT)
  183. txtFAQ.place(x=1000,y=300)
  184.  
  185. def WhereGetInfo():
  186. global txtFAQ
  187. WGI = "There are multiple reputable websites online which post content specifically related to calorie tracking and fitness goals. I chose amateur fitness vlogger Christian Guzman's YouTube video, titled: Ultimate Diet Hack: The Easiest Way to Calculate Your Own Macros. I also used the source http://www.superskinnyme.com/calculate-tdee.html."
  188.  
  189. txtFAQ.delete('1.0', 'end')
  190. txtFAQ.insert('1.0',WGI)
  191.  
  192. def WhatIsBMR():
  193. global txtFAQ
  194. WIBMR = "'Your BMR (Basal Metabolic Rate) is an estimate" \
  195. " of how many calories you'd burn if you were to do nothing but rest for 24 hours. It represents the minimum amount of energy needed to keep your body functioning, including breathing and keeping your heart beating. Your BMR does not include the calories you burn from normal daily activities or exercise.' - https://www.myfitnesspal.com/tools/bmr-calculator"
  196.  
  197. txtFAQ.delete('1.0', 'end')
  198. txtFAQ.insert('1.0',WIBMR)
  199.  
  200. def WhatIsTDEE():
  201. global txtFAQ
  202. WITDEE = "'TDEE stands for 'Total Daily Energy Expenditure', which is the total number of calories your body is burning each day - and, by extension, the number of calories that you'd need to eat each day to maintain your current weight. This is also sometimes referred to as your 'maintenance caloric intake'. Knowing your TDEE can be very useful when you're trying to determine how many calories you need to eat when you're cutting (trying to lose fat) or when you're bulking (trying to gain weight and build muscle).'-Chris Muir of Caliber"
  203.  
  204. txtFAQ.delete('1.0', 'end')
  205. txtFAQ.insert('1.0',WITDEE)
  206.  
  207. def DiffBtwMacroMicro():
  208. global txtFAQ
  209. DBMM = "'The main difference between macronutrients and micronutrients is that human body requires macronutrients in larger quantities whereas micronutrients are needed in smaller quantities. The major macronutrients are carbohydrate, protein and fat which contribute to the bulk of our food. They are the structural and energy-giving caloric constituents of our foods. Meanwhile, micronutrients such as vitamins, minerals and phytochemicals are essential for maintaining a good health.'-Pediaa"
  210.  
  211. txtFAQ.delete('1.0', 'end')
  212. txtFAQ.insert('1.0',DBMM)
  213.  
  214. def WhyProtein():
  215. global txtFAQ
  216. WP = "'Protein is made up of amino acids that help with cellular function and muscle repair. Amino acids need to be available for muscle metabolism (energy) and for ongoing anabolism (muscle growth). It will be the sufficient amount of protein intake keeping your body in a positive amino acid balance to build muscle. A decline in the balance will mean a breakdown in muscle tissue. The American College of Sports Medicine recommends a general range of 10 to 35% of your caloric intake coming from protein determined on an individual basis.' -Darla Leal of VeryWellFit"
  217.  
  218. txtFAQ.delete('1.0', 'end')
  219. txtFAQ.insert('1.0',WP)
  220.  
  221. def CalorieCount():
  222. global txtFAQ
  223. CC = "You do not have to count calories to a tee, but it is a good idea to generally eyeball your calorie intake if you want to lose or gain weight. Try apps such as MyFitnessPal or MyPlate. Monitor your portions by using smaller sized plates at the dinner table. Check out this link: https://www.prevention.com/weight-loss/g20504855/5-reasons-to-never-count-another-calorie/"
  224.  
  225. txtFAQ.delete('1.0', 'end')
  226. txtFAQ.insert('1.0',CC)
  227.  
  228. #==================================Label and Entry for Q1========================================
  229.  
  230. Height_CM=DoubleVar()
  231. Weight_KG=DoubleVar()
  232. Age=IntVar()
  233. Gender=StringVar()
  234.  
  235. def Q1abc(text, xcor1, ycor1, xcor2, ycor2,variable, width):
  236. label = Label(f1, font=('Gill Sans', 22), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
  237. entry = Entry(f1,font=('Gill Sans', 22),textvariable=variable,bd=5,insertwidth=4, width=width,fg='white',bg='darkslategray',justify='left', relief=FLAT).place(x=xcor2,y=ycor2)
  238.  
  239. return label, entry
  240.  
  241. Q1abc('Height in cm',35,117,184,110,Height_CM,5)
  242. Q1abc('Weight in kg',35,190,184,183,Weight_KG,5)
  243. Q1abc('Age',304,117,368,110,Age,3)
  244. Q1abc('Male or Female?\n(Type M or F)',304,190,478,183,Gender,3)
  245.  
  246. #==================================Label and Entry for Q2 and Q3========================================
  247.  
  248. Lifestyle = StringVar()
  249. Goal = StringVar()
  250.  
  251. def OtherQuestions(text, xcor1, ycor1, xcor2, ycor2,variable, width):
  252. label = Label(f1, font=('Gill Sans', 22), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
  253. entry = Entry(f1,font=('Gill Sans', 22),textvariable=variable,bd=5,insertwidth=4, width=width,fg='white',bg='darkslategray',justify='left', relief=FLAT).place(x=xcor2,y=ycor2)
  254.  
  255. return label, entry
  256.  
  257. OtherQuestions('2. Describe your lifestyle.',580,70,850,65,Lifestyle,3)
  258. OtherQuestions('3. Your long-term fitness goal is to:',35,300,392,293,Goal,3)
  259.  
  260.  
  261.  
  262. def ExtraStatements(text,size,xcor1,ycor1):
  263. label = Label(f1, font=('Gill Sans', size), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
  264.  
  265. return label
  266.  
  267. ExtraStatements('Respond to the following three questions.',25,35,20)
  268. ExtraStatements('1. Enter values:',25,35, 70)
  269. ExtraStatements('a) Sedentary (little to no exercise)', 15,580,110)
  270. ExtraStatements('b) Lightly active (little exercise but mostly inactive)', 15,580,140)
  271. ExtraStatements('c) Moderately active (equal parts activity and inactivity)', 15,580,170)
  272. ExtraStatements('d) Very active', 15,580,200)
  273. ExtraStatements('e) Extremely active', 15,580,230)
  274. ExtraStatements('a) Lose fat', 20,35,340)
  275. ExtraStatements('b) Gain lean mass', 20,35,380)
  276. ExtraStatements('c) Maintain weight', 20,35,420)
  277. ExtraStatements('BMR TDEE ODC',25,50,500)
  278. ExtraStatements('cal/day calories calories',25,45, 610)
  279. ExtraStatements('P C F',25,565,605)
  280. ExtraStatements('Click on any of the following buttons to learn more.',20,990,20)
  281.  
  282. #--------------B U T T O N S--------------
  283.  
  284. FinalBMR = DoubleVar()
  285. FinalTDEE = DoubleVar()
  286. FinalODC = DoubleVar()
  287. FinalProtein = DoubleVar()
  288. FinalCarbs = DoubleVar()
  289. FinalFat = DoubleVar()
  290.  
  291. def Buttons(padx, pady, size, width, height, text, command, xcor1, ycor1):
  292. button = Button(f1, padx=padx,pady=pady,bd=16,font=('Gill Sans', size), width=width, height=height,text=text,fg='white',bg = 'darkslategray',
  293. command=command).place(x=xcor1,y=ycor1)
  294.  
  295. return button
  296.  
  297. Buttons(0,0,25,14,2,'Calculate!',Calculate,580,280)
  298. Buttons(0,0,25,14,2,'Reset',Reset,580,340)
  299. Buttons(0,0,25,14,2,'Exit',Exit,580,400)
  300.  
  301. Buttons(0,0,18,14,2,'Sources?',WhereGetInfo,990,60)
  302. Buttons(0,0,18,14,2,'What is BMR?',WhatIsBMR,990,100)
  303. Buttons(0,0,18,14,2,'What is TDEE?',WhatIsTDEE,990,140)
  304. Buttons(0,0,18,34,2,'Macronutrients vs Micronutrients?',DiffBtwMacroMicro,1130,60)
  305. Buttons(0,0,17,34,2,'Why is protein emphasized in a lean diet?',WhyProtein,1130,100)
  306. Buttons(0,0,17,34,2,'Counting calories is OCD . . .',CalorieCount,1130,140)
  307.  
  308. def Entries(size,textvar,color,xcor1,ycor1):
  309.  
  310. entry = Entry(f1,font=('Gill Sans',size),textvariable=textvar,bd=5,insertwidth=4,
  311. width=4,fg='white',bg=color,justify='left', relief=FLAT).place(x=xcor1,y=ycor1)
  312.  
  313. return entry
  314.  
  315. Entries(45,FinalBMR,'MediumPurple1',35,535)
  316. Entries(45,FinalTDEE,'MediumPurple3',205,535)
  317. Entries(45,FinalODC,'MediumPurple4',375,535)
  318. Entries(30,FinalProtein,'DodgerBlue2',545,545)
  319. Entries(30,FinalCarbs,'DodgerBlue3',695,545)
  320. Entries(30,FinalFat,'DodgerBlue4',845,545)
  321.  
  322.  
  323. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement