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) win.mainloop()
This is how it looks like: