Weight Converter GUI Python project with source code

Weight conversion means to multiply the value of a unit with the standard conversion value. In this article, I will take you through how to create a weight converter GUI with Python programming language.

The standard weight conversion values include:

1 milligram = 0.001 gram
1 centigram = 0.01 gram
1 decigram = 0.1 gram
1 kilogram = 1000 grams
1 gram = 1000 milligrams
1 ton = 2000 pounds
1 pound = 16 ounces

Weight Converter GUI with Python
Now let’s see how to create a weight converter application with Python by adding some graphical user interface features. I will use the Tkinter library in Python for this task:

from tkinter import *
# Creating a GUI Window
window = Tk()
def from_kg():
    gram = float(e2_value.get())*1000
    pound = float(e2_value.get())*2.20462
    ounce = float(e2_value.get())*35.274
    t1.insert(END, gram)
    t2.delete("1.0", END)
    t2.insert(END, pound)
    t3.delete("1.0", END)
    t3.insert(END, ounce)

e1 = Label(window, text="Input the weight in KG")
e2_value = StringVar()
e2 = Entry(window, textvariable=e2_value)
e3 = Label(window, text="Gram")
e4 = Label(window, text="Pound")
e5 = Label(window, text="Ounce")

t1 = Text(window, height=5, width=30)
t2 = Text(window, height=5, width=30)
t3 = Text(window, height=5, width=30)

b1 = Button(window, text="Convert", command=from_kg)

e1.grid(row=0, column=0)
e2.grid(row=0, column=1)
e3.grid(row=1, column=0)
e4.grid(row=1, column=1)
e5.grid(row=1, column=2)
t1.grid(row=2, column=0)
t2.grid(row=2, column=1)
t3.grid(row=2, column=2)
b1.grid(row=0, column=2)


NOTE – In order to run the project of Python, you have to download Python IDLE or Pycharam. In the video I have explained how to download and install it.

Download and Install Python

Download and install Pycharm


Additional Reading


If you found this post useful, don’t forget to share this with your friends, and if you have any query feel free to comment it in the comment section.

Thank you 🙂 Keep Learning !

Leave a Reply