1 answer

Write a Python application that allows the user to convert between temperatures in Fahrenheit and temperatures...

Question:

Write a Python application that allows the user to convert between temperatures in Fahrenheit and temperatures in Celsius. Be

Write a Python application that allows the user to convert between temperatures in Fahrenheit and temperatures in Celsius. Below are the formulas for both, where Tc is temperature in Celsius and Tf is temperature in Fahrenheit: There should be 3 separate py files/classes- the Model, the View, and the Controllers. The Model contains the F/C conversion. The View is the frame. The controller runs the program and communicates between the Controller and Model

Answers

Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

Note: Make sure the below files are saved as model.py, view.py and controller.py

#code

#model.py file containing Model class

class Model:
    #method that converts temperature in celsius to fahrenheit
   
def convertToFahrenheit(self, celsius):
        return (celsius*(9/5))+32

    # method that converts temperature in fahrenheit to celsius
   
def convertToCelsius(self, fahrenheit):
        return (fahrenheit-32)*(5/9)

#view.py file containing View class    from tkinter import *   #View class is extended from Frame class of tkinter  class View(Frame):     #constructor     def __init__(self, root=None):         #invoking super class constructor         super(View, self).__init__(root)         #setting up StringVar and IntVar variables for accessing/mutating values of UI components         self.inputText = StringVar()         self.outputText = StringVar()         self.radioChoice = IntVar()         #creating required labels entries and radio buttons         Label(self, text='Input Temperature: ').grid(row=0, column=0)         #note that inputText StringVar is linked with below entry, so the contents of below         #Entry object can be accessed by calling inputText.get() and can be mutated by calling         #inputText.set(...). the same applies to other variables         Entry(self, textvariable=self.inputText).grid(row=0, column=1,columnspan=2,sticky='ew')         Label(self,text='Source: ').grid(row=1,column=0)         Radiobutton(self,text='Celsius',variable=self.radioChoice,value=1).grid(row=1,column=1)         Radiobutton(self, text='Fahrenheit', variable=self.radioChoice, value=2).grid(row=1, column=2)         Label(self, text='Output Temperature: ').grid(row=2, column=0)         Label(self, textvariable=self.outputText).grid(row=2, column=1,columnspan=2,sticky='ew')         #selecting value 1 for radio choice, which will select celsius as default source temperature         self.radioChoice.set(1)        #returns the input temperature converted to float     def getInputTemperature(self):         return float(self.inputText.get())        #updates the output label with the text provided     def setOutput(self, output):         self.outputText.set(output)        #returns True if celsius is selected as the current source temperature     def isCelsiusSelected(self):         return self.radioChoice.get()==1
#controller.py containing Controller class   import model,viewimport tkinter  class Controller:     #constructor initializing GUI     def __init__(self):         #creating a model         self._model = model.Model()         #creating a root window         root = tkinter.Tk()         #creating a view         self._view = view.View(root)         #adding view to the gui         self._view.pack()         #creating a convert button, that calls convert() method         b=tkinter.Button(root,text='Convert',command=self.convert).pack()         #staying until user clicks close button         root.mainloop()       #method to perform conversion     def convert(self):         try:             #getting input temperature             tempSource=self._view.getInputTemperature()             #getting the source temperature type             if self._view.isCelsiusSelected():                 #celsius is selected, converting to fahrenheit                 tempDest=self._model.convertToFahrenheit(tempSource)                 #displaying output with temperature rounded to 2 decimal places                 self._view.setOutput('{:.2f}F'.format(tempDest))             else:                 #converting to celsius                 tempDest = self._model.convertToCelsius(tempSource)                 self._view.setOutput('{:.2f}C'.format(tempDest))         except:             #invalid input entered             self._view.setOutput('Invalid input!')   #initializing GUI, binding view and model c=Controller()

#output

tk Input Temperature: 123 CelsiusFahrenheit Source: Output Temperature: 253.40F Convert X

.

Similar Solved Questions

1 answer
Problem 16-02A Rosenthal Company manufactures bowling balls through two processes: Molding and Packaging. In the Molding...
Problem 16-02A Rosenthal Company manufactures bowling balls through two processes: Molding and Packaging. In the Molding Department, the urethane, rubber, plastics, and other materials are molded into bowling balls. In the Packaging Department, the balls are placed in cartons and sent to the finishe...
1 answer
2. Consider the following three vectors in R: V1 where ε 10-8 (a) Using floating-point arithmetic...
2. Consider the following three vectors in R: V1 where ε 10-8 (a) Using floating-point arithmetic (i.e. assuming 1 +1), perform the original Gram-Schmidt process (b) Using floating-point arithmetic, perform the modified Gram-Schmidt process (c) Discuss the othogonality of the resulting basis...
1 answer
28. to make For which of the following compounds is it possible a 1.0M solution at...
28. to make For which of the following compounds is it possible a 1.0M solution at 20°C? (a) Cusly, solubility = 32,0g/100 ml (6) Balolt), solubility = 3.9g/100 mL (6) FeCl2, solubility = 68.5g/100 ml (d) Ca(OH)2, solubility = 0.173 g/100 ml...
1 answer
Producing robots is a very specialized process which requires special factories. There are two ways to...
Producing robots is a very specialized process which requires special factories. There are two ways to produce robots (process A and process B). It turns out that there are exactly 100 locations where you could build a type-A production facility and 100 locations where you could build a type-B facil...
1 answer
Sarah Meeham blends coffee for​ Tasti-Delight. She needs to prepare170 pounds of blended coffee beans selling...
Sarah Meeham blends coffee for​ Tasti-Delight. She needs to prepare170 pounds of blended coffee beans selling for ​$4.38 per pound. She plans to do this by blending together a​ high-quality bean costing ​$6.50 per pound and a cheaper bean at ​$2.50 per pound. To the nea...
1 answer
Where is the sun located on any diagram of earth's orbit?
Where is the sun located on any diagram of earth's orbit?...
1 answer
The heating element of a clothes dryer has a resistance of 18 . A voltage of...
The heating element of a clothes dryer has a resistance of 18 . A voltage of 220 V is connected across the heating element. What is the current in the heating element?...
1 answer
The question is from the textbook Inequality, Discrimination, Poverty, and Mobility Question 4 from chapter 5:...
The question is from the textbook Inequality, Discrimination, Poverty, and Mobility Question 4 from chapter 5: "Are workers and employers who practice reciprocity irrational?" Explain....
1 answer
Please note that "geometry" refers to the molecular or ionic geometry ?.what is the electron-pair geometry...
Please note that "geometry" refers to the molecular or ionic geometry ?.what is the electron-pair geometry for As in Asr.. ] There are ? lone pair(s) around the central atom, so the geometry ofAsF6 is B. What is the electron-pair geometry for Cl in CIFs There arelone pair(s) around the centr...
1 answer
7. + -/1 points SerPSE 10 24.A.P.047. My Notes Ask Your Teach For the configuration shown...
7. + -/1 points SerPSE 10 24.A.P.047. My Notes Ask Your Teach For the configuration shown in the figure below, suppose a = 5.00 cm, b = 20.0 cm, and c = 25.0 cm. Furthermore, suppose the electric field at a point 11.5 cm from the center is measured to be 3.90 X 10' N/C radially inward and the el...
1 answer
Currently, Forever Flowers Inc. has a capital structure consisting of 35% debt and 65% equity. Forever's...
Currently, Forever Flowers Inc. has a capital structure consisting of 35% debt and 65% equity. Forever's debt currently has an 8% yield to maturity. The risk-free rate (rRF) is 5%, and the market risk premium (rM - rRF) is 6%. Using the CAPM, Forever estimates that its cost of equity is currentl...
1 answer
Your roommate recently got an amoxicillin prescription from the Health Center for their sinus infection-like symptoms,...
Your roommate recently got an amoxicillin prescription from the Health Center for their sinus infection-like symptoms, and you see that he don’t take it particularly regularly. In fact, he throws out the half-empty bottle when he’s feeling better. You call him reckless, and your roommate...
1 answer
Why were the early U.S. political parties formed? Have changes in media formats created a more...
Why were the early U.S. political parties formed? Have changes in media formats created a more accurate, less biased media? Why or why not?...
1 answer
Question 4 What is the smallest possible value of this resistor? ohms.
Question 4 What is the smallest possible value of this resistor? ohms....
1 answer
A rope 60m long and 5cm in diameter is coiled tightly
a rope 60m long and 5cm in diameter is coiled tightly. Estimate, correct to one significant figure, the radius of the 'circle' formed. ( please could we have working out)....
1 answer
Consider a neutral soherically conducting shell of inner radius r1 and outer radius r2. a point...
consider a neutral soherically conducting shell of inner radius r1 and outer radius r2. a point charge +q, is placed at tge center (r=0) of the spherically conducting shell. Answer the following questions symbollically in terms of k,r1,r2, and q. a) what is the electric field for r>r1 b) what is ...
1 answer
Simon recently received a credit card with an 18% nominal interest rate. With the card, he...
Simon recently received a credit card with an 18% nominal interest rate. With the card, he purchased an Apple iPhone 7 for $384.43. The minimum payment on the card is only $20 per month. a. If Simon makes the minimum monthly payment and makes no other charges, how many months will it be before he pa...
1 answer
Background information: You have discovered a protein that is capable of defending agricultural crops from a...
Background information: You have discovered a protein that is capable of defending agricultural crops from a variety of insects known to negatively impact agriculture, while not creating resistance, not being harmful to non-target species, and exhibiting no negative environmental consequences. I do ...