Joe’s Automotive performs the following routine maintenance services:
• Oil change—$26.00
• Lube job—$18.00
• Radiator flush—$30.00
• Transmission flush—$80.00
• Inspection—$15.00
• Muffler replacement—$100.00
• Tire rotation—$20.00
Write a GUI program with check buttons that allow the user to select any or all of these services. When the user clicks a button the total charges should be displayed.
Program:
# import tkinter to create windows app
import tkinter as tk
# Create dictionary to store the prices of each service
service_prices = {
"Oil change": 26.00,
"Lube job": 18.00,
"Radiator flush": 30.00,
"Transmission flush": 80.00,
"Inspection": 15.00,
"Muffler replacement": 100.00,
"Tire rotation": 20.00
}
# Create a function named calculate_total().
# This function helps to calcualte the total price.
def calculate_total():
total = 0.00
for service, price in service_prices.items():
if service_vars[service].get():
total += price
total_label.config(text=f"Total Charges: ${total:.2f}")
# Create the main window
root = tk.Tk()
root.title("Joe's Automotive")
root.geometry("350x300")
# Create variables to store the check button selections
service_vars = {}
for service in service_prices:
service_vars[service] = tk.BooleanVar()
# Create check buttons for each service
for i, (service, price) in enumerate(service_prices.items()):
tk.Checkbutton(root, text=f"{service} - ${price:.2f}", variable=service_vars[service]).grid(row=i, sticky="w")
# Create the "Calculate Total" button
calculate_button = tk.Button(root, text="Calculate Total", command=calculate_total)
calculate_button.grid(row=len(service_prices), pady=10)
# Create a label to display the total charges
total_label = tk.Label(root, text="Total Charges: $0.00", font=("Arial", 12, "bold"))
total_label.grid(row=len(service_prices) + 1, pady=10)
root.mainloop()
Sample output: