Welcome folks today in this blog post we will be building a fahrenheit to celsius
temperature converter gui desktop app in tkinter using python. All the full source code of 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
#!/usr/bin/python3 # Converts Fahrenheit to Celsius import tkinter def convert_to_celsius(): fahrenheit = float(input_box.get()) celsius = (fahrenheit-32)*5/9 output_label.config(text=round(celsius, 2)) window = tkinter.Tk() window.title("C to F Converter") window.minsize(width=250, height=50) input_box = tkinter.Entry(justify=tkinter.RIGHT) output_label = tkinter.Label(text="", justify=tkinter.RIGHT, width=8) action_button = tkinter.Button(text='Convert', command=convert_to_celsius) input_box.pack(padx=20, pady=20) output_label.pack(padx=20, pady=20, side=tkinter.RIGHT) action_button.pack(padx=20, pady=20) window.mainloop() |
Now if you execute the python
script by typing the below command as shown below
python app.py