Python 3 Tkinter Script to Convert Celsius to Kelvin Temperature Converter GUI Desktop Full Project For Beginners

Python 3 Tkinter Script to Convert Celsius to Kelvin Temperature Converter GUI Desktop Full Project For Beginners

 

Welcome folks today in this blog post we will be converting celsius to kelvin temperature converter in tkinter using python. All the full source code of the application is shown below.

 

 

Get Started

 

 

In order to get started you need to make an app.py file and copy paste the following code

 

app.py

 

# -*- coding: utf-8 -*-
"""
Created on Mon Oct 22 19:26:07 2018
@author: hnambur
"""

from tkinter import Label,Entry,Button,Tk

class Converter:
    def __init__(self, master):
        self.master = master 
        master.title("A simple GUI for type conversions")
        
    def add_gui_elements(self):
        
        # Adding the header
        self.heading = Label(self.master,text="This app converts the temperature in Celcius to Kelvin")
        self.heading.grid(column=0,row=0,columnspan=2)
        # Adding the labels
        self.label = Label(self.master, text="Enter temperature in Celcius")
        self.label.grid(column=0,row=1)
        # Add the input box for taking the user input
        self.Tc_input = Entry(self.master)
        self.Tc_input.grid(column=1,row=1)
        # Add the label
        self.label2 = Label(self.master, text="Temperature in Kelvin is :")
        self.label2.grid(column=0,row=2)
        # Add the label to display the new value        
        self.label3 = Label(self.master)
        self.label3.grid(column=1,row=2)
        # Button to convert the value        
        self.convert_button = Button(self.master, text="Convert", command=self.convert)
        self.convert_button.grid(column=0,row=3,columnspan=2)

    def convert(self):
        # Utility function to convert the value
        Tc = float(self.Tc_input.get())
        T_K = Tc + 273.15
        # Put the new value back in the label
        self.label3.configure(text=str(T_K))
        
if __name__ == "__main__":
    root = Tk() # Create the main window
    my_gui = Converter(root) # Create the converter Class
    my_gui.add_gui_elements() # Add the UI elements to the window
    root.mainloop() # Launch the UI thread

 

READ  Python 3 Counting Sort Algorithm Script to Sort Strings Array Full Example Project For Beginners

 

Now if you execute the python script by typing the below command as shown below

 

python app.py

 

Leave a Reply