I made a BMI calculator with Tkinter. I have successful coded the bits where it takes the user input and calculates their BMI. One problem I'm encountering is that it only states "You are underweight/normal/obese" on the first click. After the first click, this label doesn't update anymore, but the BMI label does.
Can someone show me how I can fix this?
from Tkinter import *
import tkMessageBox
class App(object):
def __init__(self):
self.root = Tk()
self.root.wm_title("Question 7")
self.label = Label (self.root, text= "Enter your weight in pounds.")
self.label.pack()
self.entrytext = StringVar()
Entry(self.root, textvariable=self.entrytext).pack()
self.label = Label (self.root, text= "Enter your height in inches.")
self.label.pack()
self.entrytext2 = StringVar()
Entry(self.root, textvariable=self.entrytext2).pack()
self.buttontext = StringVar()
self.buttontext.set("Calculate")
Button(self.root, textvariable=self.buttontext, command=self.clicked1).pack()
self.label = Label (self.root, text="")
self.label.pack()
self.dec = Label (self.root, text="")
self.dec.pack()
self.root.mainloop()
def clicked1(self):
w = float(self.entrytext.get())
h = float(self.entrytext2.get())
bmi = float((w/(h**2))*703)
bmi = ("Your BMI is %.2f" %bmi)
self.label.configure(text=bmi)
if bmi < 18.5:
self.dec.configure(text="You are underweight")
if 18.5 <= bmi < 25:
self.dec.configure(text="You are normal")
if 25 <= bmi < 30:
self.dec.configure(text="You are overweight")
if 30<= bmi > 30:
self.dec.configure(text="You are obese")
App()