Topic: 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?
- 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 celsius temperature.
- Places the output temperature in celsius C degree 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 Fahrenheit.
- 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 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.
You would also like:
Python GUI Temperature Conversion Program Celsius to Fahrenhiet
Pingback: Find Factorial by Recursive Function Python GUI Program | EasyCodeBook.com
This blog is worth everyone’s attention. How can I find out more?
Pingback: Python GUI Multiplication Table | EasyCodeBook.com
Pingback: Python GUI Temperature Conversion Program C To F | EasyCodeBook.com