Python Pounds to Kilogram Converter GUI tkinter Program

By | March 25, 2020

Topic: Python 3 Pounds to Kilogram Converter GUI tkinter Program

How to Convert Pounds to Kilograms

We use pounds (lbs) and kilograms (kg) as units to  measure weight or mass. Both are used in different parts of the world as a weight or mass unit. Therefore, often we need to covert the Pounds to Kilograms or vice versa.

Here is the formula to convert Pounds to Kg

Since we know thtat, 1 Pound is equal to 0.454 Kilograms
or we say 1 Kilogram is equal to 2.2046 Pounds.

We can easily convert Pounds into Kgs by Dividing the number of pounds by 2.2046,
the formula is:

Kg = pounds / 2.2046

Python Pounds to Kilogram Converter GUI Program

  1. This program uses 5 Label widgets to display text in the program window
  2. The user will input the value of pounds in an entry widget.
  3. He / she will click on a button to for Lbs to Kg conversion and getting the result.
  4. The convetred result will be printed on a label
  5. Note that the formula of coversion of Pounds into Kilograms is as follows:
  6. Kg = pounds / 2.2046 (divide pounds by 2.2046)

Python Pounds to Kilogram Converter GUI

First of all we import * from tkinter module

main() function definition

The very first line is used to create the main window of this gui program.

Set the title of the main window.

Set the size and position of the main window.

Create necessary widgets to develop the GUI of the program

Place these widgets in the main window properly

Attach the functional code with the click event of the button widget.

Therefore, the user will input pounds in the text box and will click on the button.

The conversion from pounds to KG will take place and the answer will be shown on the label control.

 

# Python 3 Pounds to Kg weight Converter
# Write a Python GUI program
# using tkinter module
# to input pounds in Entry
# text box widget and convert
# to Kilograms on button click. 

from  tkinter import *

def main():
    window= Tk()
    window.title("Pounds to Kilograms Converter")
    window.geometry("450x230")
    label_easycodebook1 = Label(text="Python 3 Pounds to Kilograms Converter",
                           bg='lightgreen',font=('verdana',10))

    label_easycodebook1.place(x=25,y=5) 
    
    # create a label with text Enter Pounds
    label1 = Label(window, text="Enter Pounds:")
    
    # create a label with text Kilograms
    label2 = Label(window, text="Kilograms:")

    # place label1 in window at position x,y 
    label1.place(x=50,y=30)

    # create an Entry widget (text box) 
    #kilo = tk.StringVar()
    textbox1 = Entry(window, width=12)

    # place textbox1 in window at position x,y 
    textbox1.place(x=200,y=35)
    

    # place label2 in window at position x,y 
    label2.place(x=50,y=100)
    
    # create a label3 with empty text:
    label3 = Label(window, text=" ")

    # place label3 in window at position x,y 
    label3.place(x=180,y=100)

         
    def btn1_click():
        pounds = round(float(textbox1.get()) / 2.20462,2)
        label3.configure(text = str(pounds)+ '  Pounds')
        

    # create a button with text Button 1
    btn1 = Button(window, text="Click Me To Convert Lbs to Kg", command=btn1_click)
    # place this button in window at position x,y 
    btn1.place(x=90,y=150)

    label_easycodebook = Label(text="www.EasyCodeBook.com for Python GUI Tutorials",
                           bg='lightgreen',font=('verdana',10))

    label_easycodebook.place(x=5,y=200) 
    window.mainloop()
    

main()

Python Pounds to Kilogram Converter GUI

You may also like:

Python 3 tkinter GUI Kilogram to Pounds Program

 

 

Loading

2 thoughts on “Python Pounds to Kilogram Converter GUI tkinter Program

  1. Pingback: Python GUI Find Factorial by Recursive Function | EasyCodeBook.com

  2. Pingback: Python 3 Radio Buttons GUI Program | EasyCodeBook.com

Leave a Reply

Your email address will not be published. Required fields are marked *