Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- from tkinter import *
- from tkinter.scrolledtext import ScrolledText
- root = Tk()
- root.geometry("1600x1000+0+0")
- root.title("Ultimate Fitness Calculator")
- root.configure(bg='darkslategray')
- lbl_title = tk.Label(root,text="Welcome to the Ultimate Fitness Calculator by Cameron Su.", fg="white", bg = 'darkslategray')
- lbl_title.pack()
- #==================================Setting the Frame=======================================
- Tops = Frame(root, width=1600, height=50, bg="darkslategray", relief=SUNKEN)
- Tops.pack(side=TOP)
- f1 = Frame(root, width=1600, height=900, bg="darkslategray", relief=SUNKEN)
- f1.pack(side=LEFT)
- #==================================System Information=======================================
- lblInfo = Label(Tops, font=('Gill Sans', 50), text="Ultimate Fitness Calculator", fg="white",bg="darkslategray", bd=10, anchor='w').grid(row=0, column=0)
- 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",
- bd=10, anchor='w').grid(row=1, column=0)
- #==================================Question 1===========================================
- def Q1a_HeightCM():
- H = (float(Height_CM.get()))
- return float(H)
- def Q1b_WeightKG():
- W = (float(Weight_KG.get()))
- return float(W)
- def Q1c_Age():
- A = (float(Age.get()))
- return float(A)
- def Q1d_Gender():
- global H
- global W
- global A
- MorF = (str(Gender.get()))
- if MorF.upper() == 'M':
- BMR = (66 + (13.7*float(W)) + (5*float(H)) - (6.8*float(A)))
- return BMR
- elif MorF.upper() == 'F':
- BMR = (655 + (9.6*float(W)) + (1.8*float(H)) - (4.7*float(A)))
- return BMR
- def Q2_Lifestyle():
- global BMR
- L = (str(Lifestyle.get()))
- if L.upper() == 'A':
- TDEE = 1.2*float(BMR)
- return TDEE
- elif L.upper() == 'B':
- TDEE = 1.375*float(BMR)
- return TDEE
- elif L.upper() == 'C':
- TDEE = 1.55*float(BMR)
- return TDEE
- elif L.upper() == 'D':
- TDEE = 1.725*float(BMR)
- return TDEE
- elif L.upper() == 'E':
- TDEE = 1.9*float(BMR)
- return TDEE
- def Q3_Goal():
- global TDEE
- G = (str(Goal.get()))
- if G.upper() == 'A':
- #ODC = Optimum Daily Calories
- ODC = ((float*TDEE) - 500)
- return ODC
- Protein = 1.65*float(W)
- return Protein
- Carbs = 5*float(W)
- return Carbs
- Fat = 0.88*float(W)
- return Fat
- elif G.upper() == 'B':
- ODC = ((float*TDEE) + 500)
- return ODC
- Protein = 2.2*float(W)
- return Protein
- Carbs = 7.5*float(W)
- return Carbs
- Fat = 0.77*float(W)
- return Fat
- elif G.upper() == 'C':
- ODC = float(TDEE)
- return ODC
- Protein = 2.75*float(W)
- return Protein
- Carbs = 10*float(W)
- return Carbs
- Fat = 0.66*float(W)
- return Fat
- #--------------Functions for Buttons--------------
- def Calculate():
- global BMR
- global TDEE
- global ODC
- global Protein
- global Carbs
- global Fat
- Q1a_HeightCM()
- Q1b_WeightKG()
- Q1c_Age()
- Q1d_Gender()
- Q2_Lifestyle()
- Q3_Goal()
- FinalBMR.set(BMR)
- FinalTDEE.set(TDEE)
- FinalODC.set(ODC)
- FinalProtein.set(Protein)
- FinalCarbs.set(Carbs)
- FinalFat.set(Fat)
- def Reset():
- Height_CM.set("")
- Weight_KG.set("")
- Age.set("")
- Gender.set("")
- Lifestyle.set("")
- Goal.set("")
- FinalBMR.set("")
- FinalTDEE.set("")
- FinalODC.set("")
- FinalProtein.set("")
- FinalCarbs.set("")
- FinalFat.set("")
- txtFAQ.delete('1.0', 'end')
- def Exit():
- root.destroy()
- txtFAQ = ScrolledText(f1,font=('Gill Sans',23),bd=2,insertwidth=4, width=34, height=14,bg='DarkOliveGreen4', relief=FLAT)
- txtFAQ.place(x=1000,y=300)
- def WhereGetInfo():
- global txtFAQ
- 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."
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',WGI)
- def WhatIsBMR():
- global txtFAQ
- WIBMR = "'Your BMR (Basal Metabolic Rate) is an estimate" \
- " 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"
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',WIBMR)
- def WhatIsTDEE():
- global txtFAQ
- 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"
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',WITDEE)
- def DiffBtwMacroMicro():
- global txtFAQ
- 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"
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',DBMM)
- def WhyProtein():
- global txtFAQ
- 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"
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',WP)
- def CalorieCount():
- global txtFAQ
- 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/"
- txtFAQ.delete('1.0', 'end')
- txtFAQ.insert('1.0',CC)
- #==================================Label and Entry for Q1========================================
- Height_CM=DoubleVar()
- Weight_KG=DoubleVar()
- Age=IntVar()
- Gender=StringVar()
- def Q1abc(text, xcor1, ycor1, xcor2, ycor2,variable, width):
- label = Label(f1, font=('Gill Sans', 22), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
- 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)
- return label, entry
- Q1abc('Height in cm',35,117,184,110,Height_CM,5)
- Q1abc('Weight in kg',35,190,184,183,Weight_KG,5)
- Q1abc('Age',304,117,368,110,Age,3)
- Q1abc('Male or Female?\n(Type M or F)',304,190,478,183,Gender,3)
- #==================================Label and Entry for Q2 and Q3========================================
- Lifestyle = StringVar()
- Goal = StringVar()
- def OtherQuestions(text, xcor1, ycor1, xcor2, ycor2,variable, width):
- label = Label(f1, font=('Gill Sans', 22), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
- 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)
- return label, entry
- OtherQuestions('2. Describe your lifestyle.',580,70,850,65,Lifestyle,3)
- OtherQuestions('3. Your long-term fitness goal is to:',35,300,392,293,Goal,3)
- def ExtraStatements(text,size,xcor1,ycor1):
- label = Label(f1, font=('Gill Sans', size), text=text,fg="white",bg = 'darkslategray',bd=1, padx=10,anchor='w').place(x=xcor1,y=ycor1)
- return label
- ExtraStatements('Respond to the following three questions.',25,35,20)
- ExtraStatements('1. Enter values:',25,35, 70)
- ExtraStatements('a) Sedentary (little to no exercise)', 15,580,110)
- ExtraStatements('b) Lightly active (little exercise but mostly inactive)', 15,580,140)
- ExtraStatements('c) Moderately active (equal parts activity and inactivity)', 15,580,170)
- ExtraStatements('d) Very active', 15,580,200)
- ExtraStatements('e) Extremely active', 15,580,230)
- ExtraStatements('a) Lose fat', 20,35,340)
- ExtraStatements('b) Gain lean mass', 20,35,380)
- ExtraStatements('c) Maintain weight', 20,35,420)
- ExtraStatements('BMR TDEE ODC',25,50,500)
- ExtraStatements('cal/day calories calories',25,45, 610)
- ExtraStatements('P C F',25,565,605)
- ExtraStatements('Click on any of the following buttons to learn more.',20,990,20)
- #--------------B U T T O N S--------------
- FinalBMR = DoubleVar()
- FinalTDEE = DoubleVar()
- FinalODC = DoubleVar()
- FinalProtein = DoubleVar()
- FinalCarbs = DoubleVar()
- FinalFat = DoubleVar()
- def Buttons(padx, pady, size, width, height, text, command, xcor1, ycor1):
- button = Button(f1, padx=padx,pady=pady,bd=16,font=('Gill Sans', size), width=width, height=height,text=text,fg='white',bg = 'darkslategray',
- command=command).place(x=xcor1,y=ycor1)
- return button
- Buttons(0,0,25,14,2,'Calculate!',Calculate,580,280)
- Buttons(0,0,25,14,2,'Reset',Reset,580,340)
- Buttons(0,0,25,14,2,'Exit',Exit,580,400)
- Buttons(0,0,18,14,2,'Sources?',WhereGetInfo,990,60)
- Buttons(0,0,18,14,2,'What is BMR?',WhatIsBMR,990,100)
- Buttons(0,0,18,14,2,'What is TDEE?',WhatIsTDEE,990,140)
- Buttons(0,0,18,34,2,'Macronutrients vs Micronutrients?',DiffBtwMacroMicro,1130,60)
- Buttons(0,0,17,34,2,'Why is protein emphasized in a lean diet?',WhyProtein,1130,100)
- Buttons(0,0,17,34,2,'Counting calories is OCD . . .',CalorieCount,1130,140)
- def Entries(size,textvar,color,xcor1,ycor1):
- entry = Entry(f1,font=('Gill Sans',size),textvariable=textvar,bd=5,insertwidth=4,
- width=4,fg='white',bg=color,justify='left', relief=FLAT).place(x=xcor1,y=ycor1)
- return entry
- Entries(45,FinalBMR,'MediumPurple1',35,535)
- Entries(45,FinalTDEE,'MediumPurple3',205,535)
- Entries(45,FinalODC,'MediumPurple4',375,535)
- Entries(30,FinalProtein,'DodgerBlue2',545,545)
- Entries(30,FinalCarbs,'DodgerBlue3',695,545)
- Entries(30,FinalFat,'DodgerBlue4',845,545)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement