Skip to content
Home » Python | Tkinter GUI to Convert Temperature from Celsius to Fahrenheit 

Python | Tkinter GUI to Convert Temperature from Celsius to Fahrenheit 

In this tutorial let’s write Python Script to design Tkinter GUI to Convert Temperature from Celsius to Fahrenheit Desktop App

Python Code to create Tkinter GUI to Convert Temperature from Celsius to Fahrenheit 

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

import tkinter as Tkinter

temp_c = None
temp_f = None

def convert():

    global temp_c
    global temp_f

    try:
        val = temp_c.get()
        temp_f.set((val * 9.0 / 5) + 32)
    except:
        pass

# main window
window = Tkinter.Tk()
window.title("Temperature Converter")


frame = Tkinter.Frame(window)

frame.pack(fill=Tkinter.BOTH, expand=True)
frame.columnconfigure(1, weight=1)
frame.rowconfigure(1, weight=1)

temp_c = Tkinter.DoubleVar()
temp_f = Tkinter.DoubleVar()

# create widgets
entry_celsius = Tkinter.Entry(frame, width=7, textvariable=temp_c)
label_unitc = Tkinter.Label(frame, text="degrees C")
label_equal = Tkinter.Label(frame, text="is equal to")
label_fahrenheit = Tkinter.Label(frame, textvariable=temp_f)
label_unitf = Tkinter.Label(frame, text="degrees F")
button_convert = Tkinter.Button(frame, text="Convert", command=convert)


entry_celsius.grid(row=0, column=1, padx=5, pady=5)
label_unitc.grid(row=0, column=2, padx=5, pady=5, sticky=Tkinter.W)
label_equal.grid(row=1, column=0, padx=5, pady=5, sticky=Tkinter.E)
label_fahrenheit.grid(row=1, column=1, padx=5, pady=5)
label_unitf.grid(row=1, column=2, padx=5, pady=5, sticky=Tkinter.W)
button_convert.grid(row=2, column=1, columnspan=2, padx=5, pady=5, sticky=Tkinter.E)

entry_celsius.focus()


window.mainloop()

Output:

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

Python | Tkinter GUI to Convert Temperature from Celsius to Fahrenheit 

Similar Posts:

Tkinter | Python Script to Export Drawing 2D/3D Canvas to PDF using Tkinter with GhostScript Module
Tkinter | Python Script Convert PDF Document to Mp3 Audio Book using Tkinter with pyttsx3 Module