Python Forum
[Tkinter] rez = (mass / h) | ZeroDivisionError
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] rez = (mass / h) | ZeroDivisionError
#1
Before I post here I did some research, but still, I can't fix the problem. Are the entry fields both 0? How can I change the one of the values of the entry so the app can start or there is another way. Thank you!


from tkinter import *

root = Tk()
root.title('BMI Calculator')
root.geometry('180x200+800+400')


def bmi():
    get_height = ent_height.get()
    height = int(get_height)
    get_mass = ent_weight.get()
    mass = int(get_mass)

    h = (height * height)/1000
    rez = (mass / h)
    print(rez)

    if rez < 18.5:
        result_lbl["text"] = rez
        print("You are Underweight")
    elif rez >= 18.5 and rez < 24.9:
        print("You have Normal Weight")
    elif rez >= 25 and rez <=29.9:
        print("You are Overweight")
    elif rez > 30:
        print("You are Obese!!!")

# Create Frame
frame = Frame(height = 550)
frame.pack(fill=X)
# Create Label and Entry for Height
lbl_height = Label(frame, text = 'What is your height(Ex.180cm) ?')
lbl_height.grid(row= 0, column = 0)
ent_height = IntVar()
ent_height = Entry(frame, width=30, textvariable=ent_height)
ent_height.grid(row=1, column = 0)

# Create Label and Entry for Weight
lbl_weight = Label(frame, text='What is your weight(kg)?')
lbl_weight.grid(row= 2, column = 0)
ent_weight = IntVar(value=1)
ent_weight = Entry(frame, width = 30, textvariable=ent_weight)
ent_weight.grid(row = 3, column = 0)

# Button to calculate everything
btnCalc = Button(frame, text = 'Calculate', command = bmi())
btnCalc.grid(row = 5, column = 0)

result_lbl = Label(frame, Variable=bmi())



root.mainloop()
Reply


Messages In This Thread
rez = (mass / h) | ZeroDivisionError - by Maryan - Oct-20-2020, 02:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ZeroDivisionError: float division by zero Jionni 8 4,671 Feb-19-2020, 09:11 PM
Last Post: Jionni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020