Question
python2.7

25 Points. Create a class named BMIGUI with the following behavior. A template has been provided for you and you cannot modify the template. You must use grid) to format the interface and you must get as close as possible the layout shown below. The entry box has a width parameter in its constructor you can use to make the box smaller 3. The BMI categories are as follows: Underweight= <18.5 Normal weight18.5-24.9 . Overweight 25-29.9 Obese BMI of 30 or greater . The BMI calculation can be simplifying as follows: BMI (Weight in Pounds/(Height in inches x Height in inches)) x 703 Hint: There are 12 inches in 1 foot BMI Calculator Body Mass Index Calculator Your Height Your Weight Feet Inches Pounds Calculate BM BMI: Notice the formatting of the result: BMI Calculator Body Mass Index Calculator Your Height Your Weight Feet 8 Inches Pounds Calculate BMI BMI: 21.28 (Normal Weight) Note float values entered into the text boxes results in a custom error message for each field.
media%2Fe97%2Fe9754fe7-e089-4c9f-8074-26
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution

from tkinter import *
from tkinter import messagebox

class App(Tk):
    def __init__(self):
        Tk.__init__(self)
        self.headerFont = ("Comic Sans", "16", "bold italic")

        self.title("BMI Calculator")
        self.setInfo()

    def setInfo(self):
        Label(self, text="BMI Calculator",
              font=self.headerFont).grid(columnspan=6)

        # get user's height
        Label(self, text="Height (ft)").grid(row=1, column=0)
        self.txtHeightFt = Entry(self)
        self.txtHeightFt.grid(row=1, column=1)
        # using the insert function to default all fields to "0"


        Label(self, text="  Height (in)").grid(row=1, column=3)
        self.txtHeightIn = Entry(self)
        self.txtHeightIn.grid(row=1, column=4)


        # get user's weight
        Label(self, text="Weight (lbs)").grid(row=2, column=0)
        self.txtWeight = Entry(self)
        self.txtWeight.grid(row=2, column=1)


        # label for BMI output and status
        Label(self, text="Your BMI:").grid(row=5, column=0)
        self.lblBMI = Label(self, bg="#fff", anchor="w", relief="groove")
        self.lblBMI.grid(row=5, column=1, sticky="we")
        Label(self, text="You are:").grid(row=5, column=3)
        self.lblBMIStatus = Label(self)
        self.lblBMIStatus.grid(row=5, column=4)

        # button to calculate info
        self.btnCalc = Button(self, text="Calculate BMI")
        self.btnCalc.grid(row=10, columnspan=5)
        self.btnCalc["command"] = self.calcBMI

    def calcBMI(self):
        """calculate the BMI of a person using the formula"""

        # calculate BMI
        try:
            feet = int(self.txtHeightFt.get())
        except ValueError as v:
            messagebox.showerror("BMI Calculation ", "Error. Incorrect value entered for height(feet).")
            a.destroy()
            main()

        try:
            inches = int(self.txtHeightIn.get())
        except ValueError as v:
            messagebox.showerror("BMI Calculation ", "Error. Incorrect value entered for height(inches).")
            a.destroy()
            main()

        try:
            weight = int(self.txtWeight.get())
        except ValueError as v:
            messagebox.showerror("BMI Calculation ", "Error. Incorrect value entered for height(feet).")
            a.destroy()
            main()

        # BMI needs to be a float, int * float is float
        totalHeight = (12 * int(feet)) + int(inches)
        bmi = int(weight) * 703 / (totalHeight * totalHeight)

        self.lblBMI["text"] = "%.2f" % bmi

        # label for BMI status

        if bmi < 18.5:
            self.lblBMIStatus["text"] = "Underweight"
        elif bmi < 24.9:
            self.lblBMIStatus["text"] = "Normal Weight"
        elif bmi < 29.9:
            self.lblBMIStatus["text"] = "Overweight"
        else:
            self.lblBMIStatus["text"] = "Obese"


def main():
    global a
    a = App()
    a.mainloop()


if __name__ == "__main__":
    main()

BMI Celculstor BMI Calculator Height (ft) 5 Weight Ubs) 14q Height (in) 10 You areNormel Weight Your BM 20.09 Cakulate BMI MIFeel free to reach out regarding any queries. And please do rate the answer . Thank you .

Add a comment
Know the answer?
Add Answer to:
python2.7 25 Points. Create a class named BMIGUI with the following behavior. A template has been...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program to calculate the Body Mass Index (BMI). The formulae to calculate the BMI...

    Write a program to calculate the Body Mass Index (BMI). The formulae to calculate the BMI are BMI = (weightinPounds x 703) / (heightinInches x heightinInches ) or BMI = weightinKilograms / (heightinMeters x heightinMeters ) Your program should read the user's weight in pounds and height in inches (or, Kilograms and meters, if you prefer), calculate and display the BMI. Your program should also display a message indicating how the BMI is evaluated, based on the following BMI values:...

  • Using JAVAFX The application will calculate Body Mass Index (BMI) for people. It must be able...

    Using JAVAFX The application will calculate Body Mass Index (BMI) for people. It must be able to accept as input weights (in pounds or kilos), and height (in inches or centimeters). The application should have a calculate button, and should display the result as well as if the data puts the person in one of 4 categories underweight ( BMI < 18.5) , normal weight (BMI 18.5-24.9), overweight (BMI 25.0 - 29.9) or overweight (BMI > 30) For full credit...

  • BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that...

    BMI Class. Using JAVA write Object Oriented Programming by creating class, object and method , that takes users' input (weight and Height) and calculates the BMI. If the result is less than 18.5 display "you are underweight", if the result is greater than 18.5 display "you have a normal weight", if the result is greater than 24.9 display "your weight is considered overweight", and the result is greater than 30 display "your weight is considered as obese" (BMI = 703...

  • OGICAL 28. Body mass index (BMI) is a measure of obesity. In standard units, it is...

    OGICAL 28. Body mass index (BMI) is a measure of obesity. In standard units, it is calculated by the formula EMENTS BMI = 7032 ATEMENT NESTED INTS where Wis weight in pounds, and His height in inches. The obesity classification is BMI Classification Below 18.5 Underweight 18.5 to 24.9 Normal 25 to 29.9 Overweight 30 and above Obese Tue Write a program in a script file that calculates the BMI of a person. The program asks the person to enter...

  • /////////////////////////////////////////////////////////////////////////////////// //This program // 1. asks the user her/his weight and height // 2. then calculates...

    /////////////////////////////////////////////////////////////////////////////////// //This program // 1. asks the user her/his weight and height // 2. then calculates the user's body-mass-index (BMI) // 3. and then prints an appropriate message based on the user's BMI /////////////////////////////////////////////////////////////////////////////////// #include <iostream> using namespace std; void printWelcome(); // ask the weight (in pounds) and height (in inches) of the user and store the values in formal // parameters weight and height, respectively void getWeightAndHeight(float& weight, float& height); // calculate and return the BMI (Body-Mass-Index) based on...

  • 1. Your Body Mass Index (BMI) is a measure of your weight relative to your height....

    1. Your Body Mass Index (BMI) is a measure of your weight relative to your height. The formula can be found here: http://www.whathealth.com/bmi/formula.html (use the Imperial U.S. Method). Write an algorithm in pseudocode to calculate and display a person's BMI accepting as input their height in feet and inches and their weight in pounds. The output of your algorithm should be as follows: a. BMI b. A statement of whether the result is underweight, normal, overweight or obese.

  • Body Mass Index Calculator

    Create a BMI calculator applications that reads the user's weight in kilograms and height in meters, then calculates and displays the user's body mass index.Also, the application should display the following information from the Department of Health and Human Services, so the user can evaluate his/her BMI:BMI ValuesUnderweight: less that 18.5Normal: between 18.5 and 24.9Overweight: between 25 and 29.9Obese: 30 or greaterFormula for calculating BMI areBMI = weightInKilogramsheightInMeters x heightInMetersThe program is to be written in C++ langauge.I need some...

  • Please solve the following, please type out the code, and do not hand write because its...

    Please solve the following, please type out the code, and do not hand write because its hard to read. I would greatly appreciate it. (JAVA) Problem 1 In a class called H1P1, write a method called bmiOne that takes as arguments a mass in kilograms (a double) and a height in meters (also a double), and returns the body mass index (or BMI) for the given data. If we have mass -m kg and height-h meters, then BMI = Write...

  • Weight: 131 lbs Female Height: 5 ft 2 inches Calculate, showing the math, your Body Mass...

    Weight: 131 lbs Female Height: 5 ft 2 inches Calculate, showing the math, your Body Mass Index (BMI) using the formula 'weight in kilograms divided by height in meters squared' (kg/m^2). Note: Weight in pounds divided by 2.2 = weight in kg and height in inches times .0254 = height in meters. The number is absolute and not a percentage. Based on your BMI, are you underweight, healthy weight, overweight, or obese?

  • Write a Java program that performs these operations Prompt the user to enter a low height...

    Write a Java program that performs these operations Prompt the user to enter a low height in feet (an integer) Prompt the user to enter a high height in feet (an integer) Prompt the user to enter a low weight in pounds (an integer) Prompt the user to enter a high weight in pounds (an integer) Print a table of Body Mass Index (BMI) for the heights and weights entered, ranging from the low height to the high height (inclusive),...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT