Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Modify the temperature conversion program so that it responds to the users press of the return or enter key. If the user presses this key
Modify the temperature conversion program so that it responds to the users press of the return or enter key. If the user presses this key when the insertion point is in a given field, the action which uses that field for input is triggered. import Tkinter def CelsiusToFahenheit(Celsius, entry): #function for CelsiusToFahenheit #Celsius = int(input("Enter a temperature in Celsius: ")) Fahrenheit = 9.0/5.0 * float(Celsius) + 32 entry.delete(0, 'end') entry.insert(0, str(Fahrenheit)) def FahenheitToCelsius(Fahrenheit, entry): #function for FahenheitToCelsius #!Fahrenheit = int(input("Enter a temperature in Fahrenheit: ")) Celsius = (float(Fahrenheit) - 32) * 5.0/9.0 entry.delete(0, 'end') entry.insert(0, str(Celsius)) def main(): window = Tkinter.Tk() # Creating main window window.title("Grid") lb = Tkinter.Label(window, text='Fahrenheit')# Creating label lb.grid (row=0,column=0) lb1=Tkinter.Label(window,text='Celsius:')# Creating label lb1.grid (row=0,column=1) en =Tkinter. Entry(window, justify='right') # Creating text field en.grid(row=1,column=0) en.insert(0, "32.0") #set default value en1=Tkinter.Entry(window, justify='right') # Creating text field en1.grid(row=1,column=1) en1.insert(0, "0.0") #set default value # Creating buttons btnFtoc =Tkinter.Button(window, text='>>>>', command=lambda: FahenheitToCelsius(en.get(), en1)) btnFtoc.grid(row=2,column=0) btnCtoF =Tkinter.Button(window, text='<<<<', command=lambda: CelsiusToFahenheit(en1.get(), en)) btnCtoF.grid(row=2,column=1) window.mainloop() # Running the application if __name__ == '__main__': main()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started