Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use PYTHON 3 code. Please explain each line with comments! Write a GUI pr

ID: 3768776 • Letter: P

Question

Please use PYTHON 3 code. Please explain each line with comments!

Write a GUI program that calculates a cars gas mileage. The programs window should have Entry widgets that let the user enter the number of gallons of gas the car holds, and the number of miles it can be driven on a full tank. When a Calculate MPG button is clicked, the program should display the number of miles that the car may be driven per gallon of gas. Use the following formula to calculate miles per gallon. MPG = Miles/Gallons

Explanation / Answer

==============================================

GUI Program

==============================================

#Importing tkinter package to support GUI
from tkinter import *

#Function to calcuate MPG
def calculate_MPG():

print("MPG = %f" % (e1.get()/e2.get()))

#Creating two labels with names Miles and Gallon
master = Tk()
Label(master, text="Miles").grid(row=0)
Label(master, text="Gallon").grid(row=1)

e1 = Entry(master)
e2 = Entry(master)

e1.grid(row=0, column=1)
e2.grid(row=1, column=1)

#Creating a button with name Calulate MPG
Button(master, text='Calculate MPG', command=calculate_MPG).grid(row=3, column=0, sticky=W, pady=4)

mainloop( )

==============================================