Python PyQt Convert Pounds To Kilograms

By | September 20, 2023

Python PyQt Convert Pounds To Kilograms – To create a PyQt GUI program that converts lbs to Kgs, you can use a similar approach as in the previous examples. Here’s a basic PyQt program to perform this conversion:

<yoastmark class=

Source Code

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QLineEdit, QPushButton

class PoundsToKilogramsConverter(QWidget):
    def __init__(self):

    def initUI(self):
        self.setWindowTitle('Pounds to Kilograms Converter')
        self.setGeometry(100, 100, 300, 150)

        # Create a vertical layout
        layout = QVBoxLayout()

        # Create input field for pounds
        self.pounds_label = QLabel('Enter pounds:')
        self.pounds_input = QLineEdit()

        # Create a label to display the result
        self.result_label = QLabel('Kilograms:')

        # Create a button to perform the conversion
        self.convert_button = QPushButton('Convert')

        # Connect the button click event to the conversion function

        # Add widgets to the layout

        # Set the layout for the main window

    def performConversion(self):
            # Get the pounds value from the input field
            pounds = float(self.pounds_input.text())

            # Perform the conversion: 1 pound = 0.45359237 kilograms
            kilograms = pounds * 0.45359237

            # Display the result
            self.result_label.setText(f'Kilograms: {kilograms:.2f}')
        except ValueError:
            # Handle invalid input (e.g., non-numeric input)
            self.result_label.setText('Invalid input')

def main():
    app = QApplication(sys.argv)
    window = PoundsToKilogramsConverter()

if __name__ == '__main__':

This code creates a PyQt application with a window containing an input field for the user to enter pounds, a button to perform the conversion, and a label to display the result in kilograms. When the user enters a value in pounds and clicks the “Convert” button, the conversion is performed and displayed in the label.

Note: Make sure you have PyQt5 installed (pip install PyQt5) before running this code.


Leave a Reply

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