Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

from 

tkinter import*

W = Tk()
W.geometry('500x400+400+200')
W.title('BMI CALCULATOR')

L1 = Label(master=W, text='CHIỀU CAO',font = ('arial',15))
L1.place(x = 50, y = 65)

L2 = Label(master=W, text='CÂN NẶNG',font = ('arial',15))
L2.place(x = 50, y = 145)

E1 = Entry(master=W,font = ('arial',15),width = 12)
E1.place(x = 50, y = 100)

E2 = Entry(master=W,font = ('arial',15),width = 12)
E2.place(x = 50, y = 180)

x = IntVar()

R1 = Radiobutton(master=W,text = 'Metric',font = ('arial',15),value = 1,variable 
= x)
R1.place(x = 280, y = 80)

R2 = Radiobutton(master=W,text = 'English',font = ('arial',15),value = 2,variabl
e = x)
R2.place(x = 280, y = 130)

L3 = Label(master=W,font = ('arial',15))
L3.place(x = 170, y=65)
L4 = Label(master=W, font = ('arial',15))
L4.place(x = 170, y=145)
L5 = Label(master=W,text = 'BMI',font = ('arial',15))
L5.place(x = 215, y = 300)

def B1_click():
    if x.get() ==1:       
        L3.configure(text = '(cm) ')
        L4.configure(text = '(kg) ')
    if x.get() ==2:
        L3.configure(text = '(Inches)')
        L4.configure(text = '(pounds) ')

    h = float(E1.get())
    w = float(E2.get())
    if x.get() ==1:
        bmi = round(w/((h*h)/10000),2)
        L5.configure(text = 'BMI = ' + str(bmi))
    else:
        bmi = round((w/(h*h))*703)
        L5.configure(text = 'BMI = ' + str(bmi))

B1 = Button(master=W,text = 'CALCULATE', font = ('Arial',15),width = 12,command 
= B1_click)
B1.place(x = 170, y = 250)

W.mainloop()

You might also like