Skip to content

Instantly share code, notes, and snippets.

@Nick0603
Last active July 17, 2017 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nick0603/8c86fa844ffce41cb4bd1f486c00dddd to your computer and use it in GitHub Desktop.
Save Nick0603/8c86fa844ffce41cb4bd1f486c00dddd to your computer and use it in GitHub Desktop.
pythonDemo tinker with BMI
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