Python GUI Temperature Conversion Program C To F

By | March 29, 2020

Topic: Python GUI Temperature Conversion Program Celsius to Fahrenhiet

Python GUI Temperature Conversion Program

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


from tkinter import *

def convert_temperature():
	temp = float(entry.get())
	temp = 9/5 * temp+32
	output_label.configure(text = ' Converted to Fahrenheit: {:.1f} ' .format(temp))
	
main_window = Tk()
main_window.title("www.EasyCodeBook.com")
message_label = Label(text= ' Enter a temperature in Celsius ' ,
font=( ' Verdana ' , 12))
output_label = Label(font=( ' Verdana ' , 12))
entry = Entry(font=( ' Verdana ' , 12), width=4)
calc_button = Button(text= ' Convert C to F ' , 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 fahrenheit temperature.
  5. Places the output temperature in Fahrenheit 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 Celsius.
  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 into Fahrenheit 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 F to C degrees and displays the result.

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

You may also like: F to C Conversion Program

Python GUI ProgramĀ  Fahrenheit to Celsius

Loading

4 thoughts on “Python GUI Temperature Conversion Program C To F

  1. Pingback: Multiplication Table Python GUI Program | EasyCodeBook.com

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

  3. Pingback: Python GUI Area of Triangle | EasyCodeBook.com

  4. Pingback: Python GUI Program Temperature Conversion Fahrenheit to Celsius | EasyCodeBook.com

Leave a Reply

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