Write a temperature conversion program that converts Fahrenheit to Celsius. Use the Pack layout manager. The Fahrenheit temperature should be entered from the keyboard via an En- try component. A tkMessageBox should display the converted temperature. Use the following formula for the conversion: Celsius = 5 ? 9 * (Fahrenheit – 32)

What will be an ideal response?


```
# GUI that offers temperature conversion

from Tkinter import *
from tkMessageBox import *

class TemperatureConversion( Frame ):
"""Temperature conversion of user input"""

def __init__( self ):
"""Create an Entry and a Button component"""

Frame.__init__( self )
self.pack( expand = YES, fill = BOTH )
self.master.title( "Temperature Conversion" )
self.master.geometry( "325x100" )

# create an Entry component for the temperature
self.temperature = Entry( self, width = 30,
name = "temperature" )
self.temperature.insert( INSERT,
"Insert Fahrenheit temperature here." )
self.temperature.pack( side = LEFT, padx = 5, pady = 5 )

# create button for conversion
self.convertButton = Button( self,
text = "Convert to Celsius", command =
self.FahrenheitToCelsius )
self.convertButton.pack( side = RIGHT, padx = 5,
pady = 5 )

def display( self, information ):
"""Display converted temperature"""

showinfo( "Celsius Temperature", information )

def FahrenheitToCelsius( self ):
"""Convert Fahrenheit temperature to Celsius"""

temperature = float( self.temperature.get() )
converted = ( 5.0 / 9 ) * ( temperature - 32 )

# call display to show answer
self.display( str( converted ) )

def main():
TemperatureConversion().mainloop()

if __name__ == "__main__":
main()
```
![15062|503x116](upload://rwfssbXDez0DqZYZYo1ui8zkfGR.png)

Computer Science & Information Technology

You might also like to view...

Each item in a list box is identified by an index number. The first item in the list is assigned which of the following values as an index?

(A) a randomly assigned value (B) 1. (C) a value initially designated by the programmer (D) 0

Computer Science & Information Technology

In which of the following system authentication methods can any two stations authenticate with each other?

A. open B. closed C. selective D. binary

Computer Science & Information Technology

Probably the most often used error-handling solution before object-oriented programming was to make a decision before working with a potentially error-causing value.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

Once a data source is selected for a chart, the only way to change the data source is to start over creating the chart

Indicate whether the statement is true or false

Computer Science & Information Technology