Topic: Python GUI Temperature Conversion Program Celsius to Fahrenhiet
# 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?
- First of all, import * from tkinter module.
- Define a user defined function convert_temperature() to perform the actual conversion by using the proper formula.
- This function takes the inpuut from an entry box and converts it into float value.
- Converts celsius temperature into fahrenheit temperature.
- Places the output temperature in Fahrenheit in the output label control.
- The main program starts by creating a main GUI window.
- Sets title of main window to www.EasycodeBook.com
- Create a label with message Enter a temperature in Celsius.
- Creates an output label to display result.
- Constructs an Entry widget to take input from the user.
- A button control is created to call the convert_temperature on clicking it.
- Add controls to a grid geometry layout manager.
- Call the main loop to start the GUI. Now the program displays the main GUI window and waits for any events from the user.
- When the user enters a value in entry widget / text box and clicks the button.
- 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 Temperature Conversion Program Covert Temperature from Fahrenheit to Celsius or vice versa.
Pingback: Multiplication Table Python GUI Program | EasyCodeBook.com
Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com
Pingback: Python GUI Area of Triangle | EasyCodeBook.com
Pingback: Python GUI Program Temperature Conversion Fahrenheit to Celsius | EasyCodeBook.com