Skip to content
Home » Python | Convert Celsius to Kelvin Temperature using Tkinter

Python | Convert Celsius to Kelvin Temperature using Tkinter

In this tutorial let’s write Python Script to Convert Celsius to Kelvin Temperature using Tkinter

Python Code to Convert Celsius to Kelvin Temperature using Tkinter

app.py : You can save the below code with app.py filename.

from tkinter import Label,Entry,Button,Tk

class Converter:
    def __init__(self, master):
        self.master = master 
        master.title("Temp conversion")
        
    def add_gui_elements(self):
        self.heading = Label(self.master,text="This app converts the temperature in Celcius to Kelvin")
        self.heading.grid(column=0,row=0,columnspan=2)

        self.label = Label(self.master, text="Enter temperature in Celcius")
        self.label.grid(column=0,row=1)

        self.Tc_input = Entry(self.master)
        self.Tc_input.grid(column=1,row=1)

        self.label2 = Label(self.master, text="Temperature in Kelvin is :")
        self.label2.grid(column=0,row=2)        
        self.label3 = Label(self.master)
        self.label3.grid(column=1,row=2)      
        self.convert_button = Button(self.master, text="Convert", command=self.convert)
        self.convert_button.grid(column=0,row=3,columnspan=2)

    def convert(self):
        Tc = float(self.Tc_input.get())
        T_K = Tc + 273.15
        self.label3.configure(text=str(T_K))
        
if __name__ == "__main__":
    root = Tk() 
    my_gui = Converter(root)
    my_gui.add_gui_elements()
    root.mainloop()

Output:

To execute the code through command line, you can use python3 app.py

Convert Celsius to Kelvin Temperature using Tkinter

Similar Posts:

Python | Video Format Converter using Tkinter with FFMPEG Module
Python | Transcode and Convert Videos to GIF using Tkinter with ffmpeg Module