Last active
July 17, 2017 13:02
-
-
Save Nick0603/8c86fa844ffce41cb4bd1f486c00dddd to your computer and use it in GitHub Desktop.
pythonDemo tinker with BMI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
def calBMI(): | |
height = float(EntryHeight.get()) | |
weight = float(EntryWeight.get()) | |
BMI = weight / (height**2) | |
LabelBMI['text'] = BMI | |
if BMI < 18.5: | |
LabelResult['text'] = "體重過輕" | |
elif BMI < 24: | |
LabelResult['text'] = "正常範圍" | |
else: | |
LabelResult['text'] = "異常範圍" | |
top = Tk() | |
top.title("BMI Caculator") | |
LabelHeight = Label(top, text = "身 高( m )").grid(row=0) | |
EntryHeight = Entry(top) | |
EntryHeight.grid(row=0, column=1) | |
LabelWeight = Label(top, text = "體 重 ( kg )").grid(row=1) | |
EntryWeight = Entry(top) | |
EntryWeight.grid(row=1, column=1) | |
ButtonCal = Button(top,text = "計 算",command = calBMI).grid(row=2) | |
LabelBMIText = Label(top,text = "B M I:").grid(row=3,column=0) | |
LabelBMI = Label(top,text = "未計算") | |
LabelBMI.grid(row=3,column=1) | |
LabelResult = Label(top,text = "") | |
LabelResult.grid(row=4) | |
top.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment