[python]Simple graphic display of kilogram conversion

This is a simple graphic user interface for converting kilogram to grams, pounds and ounces.

from tkinter import *

def convert_kg():
    gram_label.set(str(int(user_input_entry.get()) * 1000)+"g")
    pound_label.set(str(float(user_input_entry.get()) * 2.20462)+"pounds")
    ounce_label.set(str(float(user_input_entry.get()) * 35.274)+"ounces")

win = Tk()

kg_label = Label(win, text="KG")
kg_label.grid(row=0, column=0)

user_input_entry = StringVar()
user_input = Entry(win, textvariable=user_input_entry)
user_input.grid(row=0, column=1)

convert_button = Button(win, text="Convert", height=1, width=10, command=convert_kg)
convert_button.grid(row=0, column=2)

gram_label = StringVar()
gram_text = Label(win, height=1, width=20, textvariable=gram_label)
gram_text.grid(row=1, column=0)

pound_label = StringVar()
pound_text = Label(win, height=1, width=20, textvariable=pound_label)
pound_text.grid(row=1, column=1)

ounce_label = StringVar()
ounce_text = Label(win, height=1, width=20, textvariable=ounce_label)
ounce_text.grid(row=1, column=2)


This is how it looks like:
Screen Shot 2018-05-01 at 10.37.42 PM.png

This entry was posted in Python, Scripting and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s