Python GUI Program Temperature Conversion Fahrenheit to Celsius

By | March 29, 2020

Topic: Python GUI Program Temperature Conversion Fahrenheit to Celsius

Python GUI Program Temperature Conversion Fahrenheit to Celsius

Python GUI Program Temperature Conversion Fahrenheit to Celsius

# Python GUI program Temperature conversion
# Faherenheit to Celsius
# Input Faherenheit Find Celsius
# www.EasyCodeBook.com


from tkinter import *

def convert_temperature():
	temp = float(entry.get())
	temp =  (temp - 32) * 5/9
	output_label.configure(text = ' Converted to Celsius: {:.1f} ' .format(temp))
	
main_window = Tk()
main_window.title("www.EasyCodeBook.com")
message_label = Label(text= ' Enter a temperature in Faherenheit ' ,
font=( ' Verdana ' , 12))
output_label = Label(font=( ' Verdana ' , 12))
entry = Entry(font=( ' Verdana ' , 12), width=4)
calc_button = Button(text= ' Convert F to C ' , font=( ' Verdana ' , 12),
command=convert_temperature)
message_label.grid(row=0, column=0)
entry.grid(row=0, column=1)
calc_button.grid(row=0, column=2)
output_label.grid(row=1, column=0, columnspan=3)
mainloop()

How This Program Python GUI Temperature Conversion Program Works?

  1. First of all, import * from tkinter module.
  2. Define a user defined function convert_temperature() to perform the actual conversion by using the proper formula.
  3. This function takes the inpuut from an entry box and converts it into float value.
  4. Converts celsius temperature into celsius temperature.
  5. Places the output temperature in celsius C degree in the output label control.
  6. The main program starts by creating a main GUI window.
  7. Sets title of main window to www.EasycodeBook.com
  8. Create a label with message Enter a temperature in Fahrenheit.
  9. Creates an output label to display result.
  10. Constructs an Entry widget to take input from the user.
  11. A button control is created to call the convert_temperature on clicking it.
  12. Add controls to a grid geometry layout manager.
  13. Call the main loop to start the GUI. Now the program displays the main GUI window and waits for any events from the user.
  14. When the user enters a value in entry widget / text box and clicks the button.
  15. The Python program will convert the temperature from Fahrenheit to celsius and displays the result in the output label control.

Here is another program with the almost same logic. The only difference is the formula used to convert the given temperature in C to F degrees and displays the result.

Temperature Conversion Visual Programming C Sharp

This is also a Python GUI Program using the tkinter module.

Loading

4 thoughts on “Python GUI Program Temperature Conversion Fahrenheit to Celsius

  1. Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com

  2. Pingback: Python GUI Multiplication Table | EasyCodeBook.com

  3. Pingback: Python GUI Temperature Conversion Program C To F | EasyCodeBook.com

Leave a Reply

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