Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from tkinter import messagebox
- BMI_INFO_CONSTANT = 'BMI INFO'
- def show_person_BMI(bmi):
- if bmi < 18.5:
- messagebox.showinfo(BMI_INFO_CONSTANT, f'{bmi} you are Underweight')
- elif 18.5 < bmi < 24.9:
- messagebox.showinfo(BMI_INFO_CONSTANT, f'{bmi} you are Normal')
- elif 24.9 < bmi < 29.9:
- messagebox.showinfo(BMI_INFO_CONSTANT, f'{bmi} you are Overweight')
- elif bmi > 29.9:
- messagebox.showinfo(BMI_INFO_CONSTANT, f' {bmi} you are Obesity')
- else:
- messagebox.showerror(BMI_INFO_CONSTANT, 'Something went wrong!')
- def calculate_bmi():
- kilograms = int(weight_in_kg.get())
- meters = int(height_in_cm.get()) / 100
- bmi = kilograms / (meters * meters)
- bmi = round(bmi, 1)
- show_person_BMI(bmi)
- root = Tk()
- var = IntVar()
- root.title('PythonGuides')
- root.geometry('400x300')
- root.config(bg='black')
- app_frame = Frame(
- root,
- padx=150,
- pady=150
- )
- app_frame.pack(expand=True)
- gender_label = Label(
- app_frame,
- bg='grey',
- text='Select Gender'
- )
- gender_label.grid(row=2, column=1)
- frame2 = Frame(app_frame)
- frame2.grid(row=2, column=2, pady=5)
- male_radio = Radiobutton(
- frame2,
- text='Male',
- variable=var,
- value=1
- )
- male_radio.pack(side=LEFT)
- female_radio = Radiobutton(
- frame2,
- text='Female',
- variable=var,
- value=2
- )
- female_radio.pack(side=RIGHT)
- height_label = Label(
- app_frame,
- bg='grey',
- text="Enter Height in CM "
- )
- height_label.grid(row=3, column=1)
- weight_label = Label(
- app_frame,
- bg='grey',
- text="Enter Weight in KG ",
- )
- weight_label.grid(row=4, column=1)
- height_in_cm = Entry(app_frame)
- height_in_cm.grid(row=3, column=2, pady=5)
- weight_in_kg = Entry(
- app_frame,
- )
- weight_in_kg.grid(row=4, column=2, pady=5)
- frame3 = Frame(app_frame)
- frame3.grid(row=5, columnspan=3, pady=10)
- calculate_BMI_button = Button(
- frame3,
- text='Calculate your BMI',
- command=calculate_bmi
- )
- calculate_BMI_button.pack(side=LEFT)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement