[PYTHON] I measured BMI with tkinter

Introduction

Recently, I often eat late at night because I go to a part-time job or a driving school. So, I thought I was fat, and I wanted to know what kind of system I am now, so I made a tool to measure BMI.

procedure

1. Display a window

qiita.py


root=tk.Tk()
root.geometry("400x300")
root.title("BMI diagnostic tool")

2. Display what you need in the window

Prepare height and weight labels, height, weight, BMI, system text boxes, and buttons. Then place them in the right places.

qiita.py


#Make a label
height_lavel=tk.Label(text="height(m)")
height_lavel.place(x=60,y=50)

weight_lavel=tk.Label(text="body weight(kg)")
weight_lavel.place(x=60,y=80)

bmi_lavel=tk.Label(text="BMI")
bmi_lavel.place(x=60,y=200)

result_lavel=tk.Label(text="What is your system?")
result_lavel.place(x=50,y=240)

#Make a text box
height_box=tk.Entry(width=20)
height_box.place(x=140,y=50)

weight_box=tk.Entry(width=20)
weight_box.place(x=140,y=80)

bmi_box=tk.Entry(width=20)
bmi_box.place(x=140,y=200)

result_box=tk.Entry(width=20)
result_box.place(x=140,y=240)

#Make a button
buttonl=tk.Button(root,text="Diagnose",font=("Halvetica",14),command=Buttonclick)
buttonl.place(x=140,y=130)

3. Consider the output conditions

Since BMI is weight (kg) / height (m) x height (m), apply this formula to output BMI. In addition, this time, when the BMI is below 18.5, the comment "Burning type", between 18.5 and 25, "Standard body type", and when the BMI is 25 or more, "Obesity" is also output.

qiita.py


    height=float(height_box.get())
    weight=float(weight_box.get())
    bmi=weight/(height*height)

    if bmi<18.5:
        result = "Skinny type"
    
    elif 18.5<=bmi<25:
        result = "Standard body type"
    
    elif 25<=bmi:
        result = "obesity"
    
    result_box.delete(0,tk.END)
    result_box.insert(0,result)

4. Press the button to run the program

qiita.py


def Buttonclick():

result

I was able to output safely.

png

Source code

qiita.py


#codimg:utf-8
import tkinter as tk

def Buttonclick():
    
    height=float(height_box.get())
    weight=float(weight_box.get())
    bmi=weight/(height*height)

    bmi_box.delete(0,tk.END)
    bmi_box.insert(0,bmi)

    if bmi<18.5:
        result = "Skinny type"
    
    elif 18.5<=bmi<25:
        result = "Standard body type"
    
    elif 25<=bmi:
        result = "obesity"
    
    result_box.delete(0,tk.END)
    result_box.insert(0,result)

#Make a window
root=tk.Tk()
root.geometry("400x300")
root.title("BMI diagnostic tool")

#Make a label
height_lavel=tk.Label(text="height(m)")
height_lavel.place(x=60,y=50)

weight_lavel=tk.Label(text="body weight(kg)")
weight_lavel.place(x=60,y=80)

bmi_lavel=tk.Label(text="BMI")
bmi_lavel.place(x=60,y=200)

result_lavel=tk.Label(text="What is your system?")
result_lavel.place(x=50,y=240)

#Make a text box
height_box=tk.Entry(width=20)
height_box.place(x=140,y=50)

weight_box=tk.Entry(width=20)
weight_box.place(x=140,y=80)

bmi_box=tk.Entry(width=20)
bmi_box.place(x=140,y=200)

result_box=tk.Entry(width=20)
result_box.place(x=140,y=240)

#Make a button
buttonl=tk.Button(root,text="Diagnose",font=("Halvetica",14),command=Buttonclick)
buttonl.place(x=140,y=130)

root.mainloop()

Impressions

For the first time, I was able to make something that works by myself with python. It took a while, but I was very happy when it was completed. Also, I think I'll try to make something like this with python even during the summer vacation.

References

―― "The easiest Python introductory class" Fumitaka Osawa [Author]

-[Python] Sample program for calculating BMI with GUI with Tkinter

Recommended Posts

I measured BMI with tkinter
MVC with Tkinter
[Python] I made a Youtube Downloader with Tkinter.
I tried playing with the calculator on tkinter
I played with wordcloud!
Become Santa with Tkinter
I made a window for Log output with Tkinter
I measured the performance of 1 million documents with mongoDB
I tried fp-growth with python
Programming with Python and Tkinter
I tried scraping with Python
I wrote GP with numpy
I made a simple typing game with tkinter in Python
Working with tkinter and mouse
I tried Learning-to-Rank with Elasticsearch!
I made blackjack with python!
I tried clustering with PyCaret
I implemented VQE with Blueqat
Screen switching / screen transition with Tkinter
Create Image Viewer with Tkinter
Let's make dice with tkinter
Run Label with tkinter [Python]
I made a puzzle game (like) with Tkinter in Python
I can't search with # google-map. ..
I tried gRPC with Python
I made COVID19_simulator with JupyterLab
I tried scraping with python
I made Word2Vec with Pytorch
I made blackjack with Python.
I tried to make GUI tic-tac-toe with Python and Tkinter
I made wordcloud with Python.
I couldn't use tkinter with python installed by pyenv of anyenv
I made a program that automatically calculates the zodiac with tkinter
I tried trimming efficiently with OpenCV
I can't install python3 with pyenv-vertualenv
I tried summarizing sentences with summpy
I tried machine learning with liblinear
I tried web scraping with python.
I tried moving food with SinGAN
I can't download images with Google_images_download
I can't install mysql-connector-python with anaconda
I made a fortune with Python.
I sent an SMS with Python
Easy GUI app with Tkinter Text
I tried implementing DeepPose with PyTorch
Async / await with Kivy and tkinter
I liked the tweet with python. ..
I tried face detection with MTCNN
I played with PyQt5 and Python3
I can't use Japanese with pyperclip
I want to do ○○ with Pandas
I played with Mecab (morphological analysis)!
I couldn't daemonize gunicorn with Fabric
I want to debug with Python
I tried running prolog with python 3.8.2.
[Tkinter] Control threads with Event object
I made a daemon with Python
[Python] Creating multiple windows with Tkinter
I tried SMTP communication with Python
I tried sentence generation with GPT-2
I tried learning LightGBM with Yellowbrick